Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Fix horizontal direction. #227

Closed
jamesst20 opened this issue Jun 21, 2014 · 8 comments
Closed

[Request] Fix horizontal direction. #227

jamesst20 opened this issue Jun 21, 2014 · 8 comments

Comments

@jamesst20
Copy link

Would it be possible to make the "horizontal" more natural. Because actually when I turn my head right, it turns left on screen which is kind of odd. Well it is normal because I am facing the camera, but it would be great to fix that :)

@sarxos sarxos closed this as completed in 2071822 Jun 21, 2014
@sarxos
Copy link
Owner

sarxos commented Jun 21, 2014

Hi @jamesst20,

Indeed, this is good feature.

You can check it by using the following JAR:

https://oss.sonatype.org/content/repositories/snapshots/com/github/sarxos/webcam-capture/0.3.10-SNAPSHOT/webcam-capture-0.3.10-20140621.155846-30.jar

WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setImageSizeDisplayed(true);
panel.setMirrored(true);

@jamesst20
Copy link
Author

@sarxos

Thanks you works perfectly! :D really appreciate it :) The only bad point is that it kills the panel repainting FPS a bit :/ I guess we can't help about that right?

@sarxos
Copy link
Owner

sarxos commented Jun 21, 2014

Hi @jamesst20, how big the FPS drop is? In regards if this can be fixed... I don't know. I would need to experiment a little bit, but this performance drop does not appear on my PC :( I constantly have ~30 FPS.

@sarxos
Copy link
Owner

sarxos commented Jun 21, 2014

@jamesst20, in regards to your previous question (about rendering acceleration). This may be interesting for you, especially the Image Scaling Performance Improvements paragraph:

http://www.oracle.com/technetwork/java/perf-graphics-135933.html

@jamesst20
Copy link
Author

Well, at default scalling, the FPS drops around 19 and if I resize the window, it drops around 9 to 10.

Running the jar this way : "java -jar WebcamTest.jar -Dsun.java2d.ddscale=true" made no difference sadly. What am I missing :/

@sarxos
Copy link
Owner

sarxos commented Jun 23, 2014

@jamesst20,

Can you please verify performance of this JAR? I made a small change to target the performance issue when image is mirrored, but it's just a blindly hit with a hope it will work.

https://oss.sonatype.org/content/repositories/snapshots/com/github/sarxos/webcam-capture/0.3.10-SNAPSHOT/webcam-capture-0.3.10-20140623.174444-34.jar

I modified:

if (mirrored) {
    x = x + w;
    w = -w;
}

gr.drawImage(image, x, y, w, h, null);

Into:

int sx1, sx2, sy1, sy2; // source rectangle coordinates
int dx1, dx2, dy1, dy2; // destination rectangle coordinates

dx1 = x;
dy1 = y;
dx2 = x + w;
dy2 = y + h;

if (mirrored) {
    sx1 = iw;
    sy1 = 0;
    sx2 = 0;
    sy2 = ih;
} else {
    sx1 = 0;
    sy1 = 0;
    sx2 = iw;
    sy2 = ih;
}

gr.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);

And here is another, very good source of information about the acceleration in BufferedImage.

http://www.jhlabs.com/ip/managed_images.html

I discovered that the problem you found was caused by the fact that image from webcam was not in the format applicable for acceleration (it was TYPE_CUSTOM instead of TYPE_INT_ARGB). Therefore, the rendering took place in the CPU, which is pretty slower than the GPU.

@jamesst20
Copy link
Author

Much better ! :)

Thanks, much appreciated :) Glad I could make you figure out a mistake !

@sarxos
Copy link
Owner

sarxos commented Jun 24, 2014

Yay! Great :) Thanks for pointing this out. I would be unaware of the rendering issue since it was working perfectly on my Ubuntu laptop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants