bug in QtKit when changing camera resolution (Bugfix #2795)


Added by nicolas martin about 12 years ago. Updated over 11 years ago.


Status:Done Start date:2013-02-12
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:highgui-camera
Target version:2.4.7
Affected version:branch '2.4' Operating System:Mac OSX
Difficulty: HW Platform:x86
Pull request:

Description

I can produce the bug with the following simple code :

#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argc, char *argv[]) {
    VideoCapture cap(CV_CAP_QT);
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
    Mat frame;
    //first frame is OK
    cap >> frame;
    imshow("image", frame);
    waitKey(10);
    //second one has the glitch
    cap >> frame;
    imshow("image", frame);
    waitKey(0);
}

The image displayed will be split in half as if there is an offset in the image data buffer.
I'm using a Logitech 9000 on Moutain Lion (10.8.2)

I tracked down the problem to the following function in modules/highgui/src/cap_qtkit.mm : void CvCaptureCAM::setWidthHeight();

It seems the capture needs to be stopped before the change and restarted after, for the change to be applied without any glitch.
The following patch seems to do the trick (the comments indicate the lines added) :

void CvCaptureCAM::setWidthHeight() {
    NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];

    //this needs to be added
    [mCaptureSession stopRunning];

    NSDictionary* pixelBufferOptions = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithDouble:1.0*width], (id)kCVPixelBufferWidthKey,
                          [NSNumber numberWithDouble:1.0*height], (id)kCVPixelBufferHeightKey,
                          [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA],
                          (id)kCVPixelBufferPixelFormatTypeKey,
                          nil];
    [mCaptureDecompressedVideoOutput setPixelBufferAttributes:pixelBufferOptions];

    //this too
    [mCaptureSession startRunning];

    grabFrame(60);
    [localpool drain];
}

Associated revisions

Revision 93af92c8
Added by Alexander Alekhin almost 11 years ago

Merge pull request #2795 from ilya-lavrenov:tapi_setto

History

Updated by Kirill Kornyakov about 12 years ago

Nicolas, thank you for the fix! We'll try to consider it for the 2.4.4 release.

Vadim, I assign this ticket to you and to 2.4.4 release. Feel free to change it in any way :) BTW, mentioned file has improper license header:

/*
 *  CvCapture.mm
 *
 *  Created by Nicholas Butko on 11/3/09.
 *  Copyright 2009. All rights reserved.

  • Category set to highgui-camera
  • Target version set to 2.4.4
  • Priority changed from High to Normal
  • Tracker changed from Bug to Bugfix
  • Assignee set to Vadim Pisarevsky

Updated by Andrey Kamaev about 12 years ago

  • Target version changed from 2.4.4 to 2.4.5

Updated by Andrey Kamaev almost 12 years ago

  • Target version changed from 2.4.5 to 3.0

Updated by Steven Puttemans over 11 years ago

Added a pull request for the fix: https://github.com/Itseez/opencv/pull/1152/files

  • Target version changed from 3.0 to 2.4.7

Updated by Alexander Shishkov over 11 years ago

Fixed. Thanks to Nikolas and Steven.

  • HW Platform set to x86
  • Operating System set to Mac OSX
  • Affected version changed from 2.4.3 to branch '2.4'

Updated by Steven Puttemans over 11 years ago

Fix merged! Problem solved :)

  • Assignee deleted (Vadim Pisarevsky)
  • Status changed from Open to Done
  • % Done changed from 0 to 100

Also available in: Atom PDF