Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open webcam and set as background (question)

Best reader,

I'm stuck on one of my concepts. I'm making a program which classroom children can measure themselves with. This is what the program includes; - 1 webcam (only used for a simple webcam view.) - 2 phidgets (don't mind these.)

So, this was my plan. I'll draw a rectangle on the webcamview and make it repaint itself constantly. When the repainting is stopped by one of the phidgets, the rectangle's value will be returned in centimeters or meters.

I've already written the code of the rectangle that's repainting itself and this was my result:

(It's a roundRectangle, the lines are kind of hard to see in this image, sorry about that.) enter image description here

As you can see, the background is now simply black. I want to set the background of this JFrame as a webcam view (if possible) and then draw the rectangle over the webcam view instead of the black background.

I've already looked into jmf, fmj and such but am getting errors even after checking my webcam path and adding the needed jar libraries. So I want to try other options.

So; - I simply want to open my webcam, use it as background (yes live stream, if possible in some way). And then draw this rectangle over it. I'm thus wondering if this is possible, or if there's other options for me to achieve this.

Hope you understand my situation, and please ask if anything's unclear.

EDIT: I got my camera to open now trough java. The running camera is of type "Process". This is where I got the code for my camera to open: http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/ I adjusted mine a little so it'll open my camera instead. But now I'm wondering; is it possible to set a process as background of a JFrame? Or can I somehow add the process to a JPanel and then add it to a JFrame? I've tried several things without any succes.

My program as it is now, when I run it, opens the measuring frame and the camera view seperatly. But the goal is to fuse them and make the repainting-rectangle paint over the camera view.

Help much appreciated!

like image 609
Antique Avatar asked Apr 07 '11 18:04

Antique


1 Answers

I don't think it's a matter of setting a webcam stream as the background for your interface. More likely, you need to create a media player component, add it to your GUI, and then overlay your rectangles on top of that component.

As you probably know from searching for Java webcam solutions in Stack Overflow already, it's not easy, but hopefully the JMF Specs and API Guide will help you through it. The API guide is a PDF and has sections on receiving media streams, as well as sample code.

like image 147
BoffinBrain Avatar answered Oct 26 '22 12:10

BoffinBrain