Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Focus webcam before snapping image with OPENCV

How do I enable the webcam to auto focus before snapping the image?

My code for capturing the image is as shown:

{
    CvCapture* capture = cvCaptureFromCAM(0); // capture from video device #0


    cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_WIDTH , 800); 
    cvSetCaptureProperty(capture ,CV_CAP_PROP_FRAME_HEIGHT , 600); 


    if(!cvGrabFrame(capture))  //if no webcam detected or failed to capture anything
    {              
        cout << "Could not grab a frame\n\7";
        exit(0);
    }

    IplImage* img=cvRetrieveFrame(capture);           // retrieve the captured frame
}

I have tried using wait key, etc, tried googling but to no avail. Does anybody have any idea how I can ensure that autofocus is applied already before snapping the image? Cuz the image now is a little more "blurry" than I would like it.

like image 610
rockinfresh Avatar asked Jan 23 '26 03:01

rockinfresh


1 Answers

According to this page "Logitech webcam B910, C910 and C920 Auto-focus fix" it seems that the focus on Logitech C920 webcam is factory adjusted for short and medium distances. The same page has some instructions about changing the factory setup.

like image 76
Alessandro Jacopson Avatar answered Jan 25 '26 23:01

Alessandro Jacopson