Go to Post using CD to answer my question is not the way to get the "ALL-BINDING FIRST ANSWER." - rees2001 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-02-2016, 19:48
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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();
processImage:
Code:
 		videoCapture.read(matOriginal);
 		if(matOriginal.empty()) {
 			break;
 		}
Im not really sure why but it seems like the image is empty. I tried putting the image grabbing in a loop, because I hear it could take a while to grab an image. However, no dice.

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   Spotlight this post!  
Unread 09-02-2016, 20:36
Turing'sEgo Turing'sEgo is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2010
Location: Boulder
Posts: 47
Turing'sEgo can only hope to improve
Re: OpenCV C++ Bad file descriptor. USB Lifecam

Instead of videoCapture.read(matOriginal), try videoCapture >> matOriginal.
  #3   Spotlight this post!  
Unread 09-02-2016, 22:28
PaulDavis1968's Avatar
PaulDavis1968 PaulDavis1968 is offline
Embedded Software/Systems Engineer
AKA: Master of Complexity
FRC #2053 (TigerTronics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Endicot NY
Posts: 91
PaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nicePaulDavis1968 is just really nice
Re: OpenCV C++ Bad file descriptor. USB Lifecam

Quote:
Originally Posted by Turing'sEgo View Post
Instead of videoCapture.read(matOriginal), try videoCapture >> matOriginal.
I can't remember Drew, but did we not try that?
  #4   Spotlight this post!  
Unread 09-02-2016, 22:29
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
Re: OpenCV C++ Bad file descriptor. USB Lifecam

Yes, we did try that and had the same effect.
  #5   Spotlight this post!  
Unread 09-02-2016, 23:03
Turing'sEgo Turing'sEgo is offline
Registered User
no team
 
Join Date: Jan 2016
Rookie Year: 2010
Location: Boulder
Posts: 47
Turing'sEgo can only hope to improve
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   Spotlight this post!  
Unread 10-02-2016, 05:29
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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 cant run the command you gave me because it cant find the command sudo. I used 2168's opencv library's. I'm not sure if that makes a difference. I moved the videoCapture = cv::VideoCapture(); and .open(0) outside the loop and it makes no difference.

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   Spotlight this post!  
Unread 10-02-2016, 16:48
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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   Spotlight this post!  
Unread 11-02-2016, 13:18
KJaget's Avatar
KJaget KJaget is offline
Zebravision Labs
FRC #0900
Team Role: Mentor
 
Join Date: Dec 2014
Rookie Year: 2015
Location: Cary, NC
Posts: 44
KJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud ofKJaget has much to be proud of
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   Spotlight this post!  
Unread 11-02-2016, 18:13
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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;
    }
}
I'm honestly completely confused because multiple teams have had this working with no issue.
  #10   Spotlight this post!  
Unread 12-02-2016, 11:33
jreneew2's Avatar
jreneew2 jreneew2 is offline
Alumni of Team 2053 Tigertronics
AKA: Drew Williams
FRC #2053 (TigerTronics)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Vestal, NY
Posts: 203
jreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura aboutjreneew2 has a spectacular aura about
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
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi