|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
OpenCV C++ Bad file descriptor. USB Lifecam
Hello all, I am having an issue with the USB Lifecam and getting an image to an an openCV mat. My code works fine with an axis camera, but because ours broke a couple days ago I am trying to get the USB camera to work with the code. It opens the stream fine, but ends up with a width and height of zero. The error log is:
Code:
IM AM IN PROCESS IMAGE! VIDIOC_QBUF: Bad file descriptor Unable to stop the stream.: Bad file descriptor munmap: Invalid argument munmap: Invalid argument munmap: Invalid argument munmap: Invalid argument Here is our code: Code:
// opens up the camera stream and tries to load it
videoCapture = cv::VideoCapture();
// replaces the ##.## with your team number
videoCapture.open(0);
// Example
// cap.open("http://10.30.19.11/mjpg/video.mjpg");
// wait until it is opened
while(!videoCapture.isOpened()){
printf("videoCapture could not open!\n");
}
// time to actually process the acquired images
processImage();
Code:
videoCapture.read(matOriginal);
if(matOriginal.empty()) {
break;
}
I'm really hoping someone else has had a similar issue because our team cannot afford another axis camera. Thanks, Drew Last edited by jreneew2 : 09-02-2016 at 19:53. Reason: added info |
|
#2
|
|||
|
|||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
Instead of videoCapture.read(matOriginal), try videoCapture >> matOriginal.
|
|
#3
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
I can't remember Drew, but did we not try that?
|
|
#4
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
Yes, we did try that and had the same effect.
|
|
#5
|
|||
|
|||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
I figured it wouldn't make a difference but you never know.
Would you link to all your vision code so I can take a look at it and play around with it? A fairly simple thing you could try would be to reinstall opencv through terminal: sudo apt-get remove --purge opencv sudo apt-get install libopencv-dev This won't give you gpu support (I don't think at least), but it's better to have something than nothing. Edit 1 I found your code on another thread. A thing I found was that you declare videoCapture, then inside a while loop you say: videoCapture = cv::VideoCapture(); Seems a little redundant. I'm not sure this is the cause to your error or not. Moving on to the next line, videoCapture.open("http://axis-camera.local/mjpg/video.mjpg"); isn't wrong, but it may be incorrect to have it in a while loop.... Edit 2 I just tested calling .open(0) in a while loop. While it did run, it ran at <1fps. I also tested having videoCapture = cv::VideoCapture(); inside a while loop too, and all it did was further bog down the program. Could you run in debugger mode and let me know which line is causing the error? Edit 3 Giving this a little more thought: I am not rehearsed in IP cameras, so this could be completely off, but... Would you test the following code for me? http://pastebin.com/6vrLBVtE Last edited by Turing'sEgo : 09-02-2016 at 23:37. |
|
#6
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
Yes. I will test it tonight. Thank you for all the help.
I just tried the code you posted and it did not work. This was the error I got. Code:
VIDIOC_REQBUFS: Cannot allocate memory VIDIOC_QBUF: Bad file descriptor No frame OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/OpenCVArm/opencv-2.4.10/modules/highgui/src/window.cpp, line 261 Unable to stop the stream.: Inappropriate ioctl for device munmap: Invalid argument munmap: Invalid argument munmap: Invalid argument munmap: Invalid argument terminate called after throwing an instance of 'cv::Exception' what(): /home/OpenCVArm/opencv-2.4.10/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow I'm pretty sure it connects to the camera find but it grabs an empty frame for some reason. Thanks. Last edited by jreneew2 : 10-02-2016 at 16:47. Reason: Added info and reply |
|
#7
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
Also, it works fine with the axis camera and connects, just not the usb. But, we cant use the axis camera because it broke a couple of days ago.
|
|
#8
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
How about just opening the camera using :
cv:VideoCapture videoCapture(0); That should be enough to open the camera and use it. All of the other stuff is just extra steps that could go wrong. There's a simple example at http://docs.opencv.org/2.4/modules/h...videocap ture which should just work if you want to rule out the rest of the code being the problem. |
|
#9
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
I tested out the example code and it still says bad file descriptor still. I have the most simple code and still the same error.
Here it is: Code:
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
void testVision() {
cv::VideoCapture vcap(0);
cv::Mat image;
//open the video stream and make sure it's opened
std::cout << "in testVision" << std::endl;
std::cout << "about to go into loop" << std::endl;
while(1) {
std::cout << "in loop" << std::endl;
vcap >> image;
//std::cout << "No frame" << std::endl;
std::cout << "Width: " << image.cols << std::endl;
std::cout << "Height: " << image.rows << std::endl;
//if(cv::waitKey(1) >= 0) break;
}
}
|
|
#10
|
||||
|
||||
|
Re: OpenCV C++ Bad file descriptor. USB Lifecam
Alright, I got the USB camera working. I reimaged the roboRIO, installed opencv 3.0 on the roboRIO and now it works! Thanks to the robotpy who helped me get this working and their repository with opencv code.
Their code is here:https://github.com/robotpy/roborio-opencv |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|