Ask Your Question
1

Opencv select timeout at high resolutions

asked 2016-12-29 01:50:36 -0500

Saghir Khatri gravatar image

Hi all. I have an A4Tech pk-336e webcam attached with my BeagleBone and i am using OpenCV to capture images from BeagleBone Black. Issue is when i capture image at 320x240 resolution i get a perfect image but at 640x480 i get select timeout. Although it is written on camera that it supports 640x480 when i type the following command

v4l2-ctl --all

My code to capture image is as follows:

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main( )
{
    cout <<"Start main"<<endl;
    VideoCapture cap(0); // open the default camera
    cap.set(CV_CAP_PROP_FRAME_WIDTH , 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT ,480);

    Mat meter_image;
    cap >> meter_image;
    imwrite("/card/imgs.jpg", meter_image);
    return 0;
}

I know its really common issue but i am not sure where i can find the solution as i am able to make it working with Logitech one. Kindly let me know of any thing which helps in solving this... Regards

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2017-04-04 09:00:20 -0500

Acherrum gravatar image

updated 2017-04-05 04:17:26 -0500

I'm actually experiencing a similar problem with OpenCV 3.2.

I had the exact same problem on Ubuntu 16.04 Minimal. So yesterday I switched to Debian Jessie and now the problem has evolved to the next stage ;)

Here's what you could try (what I did to troubleshoot and test).

sudo apt-get install fswebcam

After that, run this and check if it works:

sudo fswebcam -r 640x480 --jpeg 95 -D 1 test.jpg

The fun thing about fswebcam is that it actually gives you some nice debug information right there ;) So, hopefully, that program is able to grab the picture and save it for review. It was for me. If it still doesn't work, you might want to rebuild your OS, or switch to something else.

Now I went back to OpenCV and found out that I still get Select Timeout, but only once. After the timeout, I immediately get correct grab.

EDIT: I seem to have just fixed my issue. It was a bandwidth issue with the uvcvideo module.

# rmmod uvcvideo
# modprobe uvcvideo quirks=128 nodrop=1 timeout=6000

I added that to my .bash_profile, and I'm now succesfully grabbing 100 1600x1200 photo's @ 5FPS ;) I do occassionally get a Corrupted JPEG data: premature end of data segment, but so far, less than 10% of the time. I'm still looking into fixing those ;)

edit flag offensive delete link more
0

answered 2016-12-29 02:39:29 -0500

pi-null-mezon gravatar image

the VideoCapture::set method does not guarantee anything, so change the code and see what happens

#include <opencv2/objdetect/objdetect.hpp>
...

int main( )
{
    cout <<"Start main"<<endl;
    VideoCapture cap; // open the default camera
    if(cap.open(0)) {
       cap.set(CV_CAP_PROP_FRAME_WIDTH , 640);
       cap.set(CV_CAP_PROP_FRAME_HEIGHT ,480);

       if((int)cap.get(CV_CAP_PROP_FRAME_WIDTH) != 640
           || (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT) != 480)
            std::cout << "Warning! Can not adjust video capture properties!" << std::endl;

       Mat meter_image;
       if(cap.read(meter_image)) {
            imwrite("/card/imgs.jpg", meter_image);
            cap.release();
            return 0;
       } else {
           cap.release();
           return -1; // can not read frame
       }
    } else {
         return -2; // can not open video capture device
    }
}
edit flag offensive delete link more

Comments

I got select timeout after running your code.. So its not related to ViceoCapture::set method. Any other thing i can look into??

Saghir Khatri gravatar imageSaghir Khatri ( 2016-12-30 00:56:53 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-12-29 01:50:36 -0500

Seen: 3,462 times

Last updated: Apr 05 '17