-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
WebCam Capture Performance #246
Comments
Hi @rakeshbhatt10 , Please clarify:
|
Hi @sarxos What is the API version you was testing against? How was the tests executed (What was the light etc)? What do you mean by Refresh rate? Additional info:
Dimension requiredDimension = new Dimension(resX,resY);
Dimension[] dime = {requiredDimension};
Webcam webCam = Webcam.getWebcams().get(cameraid);
webCam.setCustomViewSizes(dime);
webCam.setViewSize(requiredDimension);
WebcamPanel webCamPanel = new WebcamPanel(webCam);
webCamPanel.setFPSDisplayed(true);
webCamPanel.setDisplayDebugInfo(true);
webCamPanel.setImageSizeDisplayed(true);
webCamPanel.setMirrored(true);
contentPane.add(webCamPanel,BorderLayout.CENTER); I had tried with webCamPanel.setMirrored(false) or removed it but there is no difference
I want to know the reason why this actually happens. I had been hanging with these issues throughout the development Thanks, |
HI @rakeshbhatt10, Thank you for the clarification. The FPS should be pretty stable between the operating systems whenever application is run on the machine with comparable processing power. It depends on the following aspects:
The refresh rate is a average speed of how WebcamPanel is being rendered. This value depends on the following:
If you are curious of how Java rendeing/acceleration works: http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/java2d.html I hope the above clarifies your doubts. |
Hi @sarxos Thanks a lot for providing your inputs on this problem I am completely agree @sarxos with your points on Processing Power, GPIO speed and Image Resolution. You had described them very well. "I want to ask that how under same lighting condition on low processors Logitech WebCam software provides much more better webcam preview output." There is no lagging nothing at all with higher resolution too with Logitech WebCam Software. i have seen the same capability in Skype as well with Logitech webcams. As you have describe the points which are reason for slow webcam preview. Is there can be any better way to achieve the same performance as Logitech WebCam Software in Java ? |
@rakeshbhatt10, in regards to Logitech WebCam Software, I can only have my own suspicions, can only guess why this software is faster. Those are my more or less probable thoughts:
|
Thanks @sarxos for this explanation I am also trying to use another camera from different vendors. I had tried with other cameras from e-consystesm in this link As per the hardware specification FPS rate is higher in MJPEG format I had tried below code to capture MJPEG from webcam checked in chrome. Performance is worse Webcam webCam = Webcam.getWebcams().get(1);
Dimension[] prefDimension ={ new Dimension(640,480)};
webCam.setCustomViewSizes(prefDimension);
webCam.setViewSize(prefDimension[0]);
WebcamStreamer web=new WebcamStreamer(8080, w, 0.5, true);
do {
Thread.sleep(5000);
} while (true); There is any way i can integrate MPEG with WebCamPanel. Will it increase any performance of webcam capture on low processors ? |
Hi @rakeshbhatt10, Unfortunately for you, Webcam Capture API in all cases uses YUV format. The example you posted reads the RAW image from camera in YUV format and transcode it to MJPEG stream used by web browser. The MJPEG support has been planned as enhancement #145, but I never had enough time to implement it (constantly busy at work) :( |
Hi @sarxos, Is there a way to access directly to the RAW image from camera ? I need access to original format YUV422i, that my camera streams. (I want to avoid RGB conversion) Thank you for your time. Andrei |
Hi @cosmac, With existing implementation I'm afraid this is not possible. |
Hi @sarxos , Thank you for your fast reply. It is almost impossible to find something like that :) OpenCV states that you should be able to save YUV format, but actually it is not implemented. All the frames are converted to RGB no matter what format comes from cameras. Thank you again! |
Hi @cosmac, From what I remember OpenCV uses slightly modified VideoInput lib which is also used by the Webcam Capture API default driver. Unfortunately, it chooses format automatically (loop through the list and select RGB24). However, you could try Java bindings for GStreamer. There is a version compatible with GS 0.10.x available from Google Code (please note people reported having problems finding 64-bit version of this stuff, but if you decide to use 32-bit you have to have 32-bit Java as well): https://code.google.com/p/gstreamer-java It's used by my GStreamer capture driver (see webcam-capture-driver-gstreamer) so in any case you do not have to start from scratch. There is also version compatible with GS 1.x available here on Github. It uses one of the most recent GStreamer releases: https://github.com/gstreamer-java/gst1-java-core There is also example demonstrating how it can be used with webcam: In regards to GS 1.x I'm planning to prepare dedicated capture driver to replace previous old 0.10.x but first I need to handle stuff at work so I have some spare weekends to donate into the project (games industry is tough sometimes). Just for your information, in GStreamer Java code you can iterate over // create and bind everything together (pipeline, source, sink, filters, etc)
Pad pad = source.getPads().get(0)
Caps caps = pad.getCaps();
for (int i = 0, n = caps.size(); i < n; i++) {
System.out.println(caps.getStructure(i).getName()); // e.g. "video/x-raw-yuv"
} Also you can create String format = ... // find the format matching YUV422i
Caps caps = Caps.fromString(String.format("%s,width=%d,height=%d",
format, size.width, size.height));
filter.setCaps(caps); // this will cause given format to be used Here is how I'm doing this, but this still takes RGB as a priority (YUV gave me less FPS so I'm using it in second place if there is no RGB support): I would lie if I say that GStreamer impl is easy but if you choose this path I'm sure GStreamer Java community will help you. |
Hi @sarxos , Thank you so much for your detailed feedback. I will follow this path and see if I can achieve something. |
@sarxos if you feel you have too much on your plate please feel free to assign some of the little issues to me. :) |
@peterchaula please feel free to select any issue you want and send pull request for it. I will be happy to review :) |
Hey! Now i'm having a performance issue which i cannot solve, and i'm not sure if it is possible at the moment. So... the WebcamCapture API is really nice, and perfectly fits my needs. The only problem is this performance issue i spent already 2 days on. Edit: i don't get 5 FPS, but the repaints per second are about 5. So, the FPS (shown in the webcampanel) stay constant about 30. But the repaints are getting lower, the higher i set the resolution |
Hi @sarxos ,
I had implemented your solution and tested on various processors i3 ( 4 GB RAM), i5 (4 GB RAM) , Core 2 Duo and Atom with different webcams. I had noticed that in every system FPS as well as Refresh rate gets changed. In some systems i had seen changes in application where FPS is good but refresh rate is slow. I had been trying with Logitech C920 webcam as external cam.
I didn't get why these changes happens. When i test Webcam with Logitech WebCam software It's performance of webcam preview remains constant in all systems even with high resolutions. I didn't get it.
It will be very helpful if you can provide your suggestions
Thanks in advance
The text was updated successfully, but these errors were encountered: