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

How to add overlay frame to webcam pane. is it possible to add frame to camera? or can i draw something on camera? else can i put image on webcam pane? #282

Closed
dhavaljoshi43 opened this issue Dec 2, 2014 · 10 comments
Labels

Comments

@dhavaljoshi43
Copy link

Hello. I want to know if i want to capture image that is overlayed by one trasparent frame. transparent frame can be one image also. so When i click the photo there is frame in it? help to resolve my issue? kindly help me..
a

@sarxos
Copy link
Owner

sarxos commented Dec 2, 2014

Hi @dhavaljoshi43,

You can either draw some image on the panel (WebcamPanel) that displays image from the camera and left the original camera feed untouched, so you will see modified image when you view camera image with WebcamPanel, but when you save the image to file, and open this file, there will be no modification (you will see original image from camera feed). This approach can be implemented by use of WebcamPanel.Painter interface. The example of how to implement painter feature can be found here.

The other possibility, where you modify the original image that comes with camera feed, is to use WebcamImageTransformer interface on the Webcam itself. This approach will modify the original image feed in such a way, that you will see modified image when you open camera with WebcamPanel but also when you save image into file and then remove in another application. The image will be the same as you saw in WebcamPanel. The example of how to use this feature can be found here (although it's only turning the image to grayscale).

Depending on your needs you can choose one of the above.

@sarxos sarxos added the question label Dec 2, 2014
@dhavaljoshi43
Copy link
Author

Second approach is suitable to me.. but how to draw frame on WebcamImageTransformer class? is it possible to do anything with that? can we set any image to this class? trasparent image like I mentioned above?
Thanks for reply!!

sarxos added a commit that referenced this issue Dec 2, 2014
sarxos added a commit that referenced this issue Dec 2, 2014
@sarxos
Copy link
Owner

sarxos commented Dec 2, 2014

Of course it is possible :) Have you take a look at the example from my previous post? This is very simple example that turns image into grayscale, but you can do with the image practically anything. More sophisticated example I crafted just before a minutes ago can be found here:

webcam-capture-transformer

I guess it does exactly what you are trying to achieve, so I will not explain how to use it - just take a look into the code. I guess it's fairy simple to understand.

WebcamImageTransformerExample.java

The effect:

image

Take care!

@sarxos sarxos closed this as completed Dec 2, 2014
@dhavaljoshi43
Copy link
Author

Awesome Man Awesome!! Right now I am not on my desk. I will implement tomorrow. then I get back to you. Thanks a lot for now! you have developed awesome API among all. All the best. Take care! Good Night.

@dhavaljoshi43
Copy link
Author

Hello Very Good Morning @sarxos.
I implemented your code into my App..it succesfully place frame on my screen but when I try to get picture it returns me blank black screen? why is this happen?

Using this code I captured image :

BufferedImage image = selWebCam.getImage();
// save image to JPG file
ImageIO.write(image, "JPG", new File("/home/ubuntu/" + System.currentTimeMillis() + ".jpg"));

problems in saving only in JPG format. If i used PNG then works Fine.

@sarxos
Copy link
Owner

sarxos commented Dec 3, 2014

Hi @dhavaljoshi43,

The issue you are struggling is caused by the very fundamental difference between JPEG and PNG. The JPG consist of RGB channels, and PNG consists of ARGB (where A stands from Alpha). So it is very important to use appropriate BufferedImage type - RGB or BGR for JPEGs only and ARGB , ABGR, RGB or BGR for PNGs (for all possible types see JavaDoc, the Fields section). There is also additional image type described as premultiplied where Alpha is mixed within the other channels, but I will not be explaining how it works. There are dozens of resources on the Google where you can read about how the image data can be represented and stored, but in all cases, when you use incorrect image type, the effect is only black image, pink image, shifted colours, etc.

Ok, now to the core of your problem. As I stated above, you need to use RGB instead of ARGB, so it's enough to change this:

BufferedImage modified = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

Into this:

BufferedImage modified = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

I will change the source code to eliminate the types dissonance.

@mehmetbektas
Copy link

Thanks for labor.
İn this repository there is live streaming example. i tried it on. But it didnt work because of H264Encoder class. i use xuggle-xuggler-noarch-5.4 jar. What version of xuggler library can i use for live stream?

@dhavaljoshi43
Copy link
Author

Thanks @sarxos now Its works perfectly!! thanks for help.

@sarxos
Copy link
Owner

sarxos commented Dec 3, 2014

@dhavaljoshi43, you're welcome :)

@mehmetbektas, the live streaming example available under the link below works well (was tested on WinXP, Win7, Ubuntu 12 and 14). Please note it's not a reference implementation, just a POC (proof-of-concept), so in case you find any issue with the example code you have to fix it on your own.

webcam-capture-live-streaming

All dependency versions are available in pom.xml of this project. The Xuggler, as you can see, is xuggle-xuggle-5.4.jar and can be found in Xuggler repository under the corresponding group ID:

http://xuggle.googlecode.com/svn/trunk/repo/share/java/xuggle/xuggle-xuggler/5.4/

Please also create a separate issue next time in case of questions not related the the original issue subject. I would like to avoid mixing topics that are not related, so we have everything organized and clear. Thanks.

@mehmetbektas
Copy link

i have done it. thanks again

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

No branches or pull requests

3 participants