Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

capture video from my web cam only shows gray.

trying to capture video from my web cam only shows gray.

Using Visual Studio 2012 - C++/Qt.

this is what i get when i try to capture the frames: i.imgur.com/x7zYVAX.jpg

some code:

    qDebug() << "button 0 clicked." << endl;

    //Opens the video device #0.
    cap = new VideoCapture(0);
    if (!cap->isOpened())
    {
        qDebug() << "Cannot open the video file" << endl;
        return;
    }

    cv::Mat srcFrame;
    //read a new frame from video.
    bool bSuccess = cap->read(srcFrame);
    if (!bSuccess)
    {
        qDebug() << "Cannot read a frame from video device." << endl;
        return;
    }

    scene->addPixmap(QPixmap::fromImage(Mat2QImage(srcFrame), Qt::AutoColor));

QImage MainWindow::Mat2QImage(cv::Mat const& src)
{
     cv::Mat temp; // make the same cv::Mat
     cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
     QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
     QImage dest2(dest);
     dest2.detach(); // enforce deep copy
     return dest2;
}

my .pro file:

win32 {

    INCLUDEPATH += C:/opencv/build/include
    LIBS += -LC:/opencv/build/x86/vc11/lib

    CONFIG(debug, debug|release) {
        LIBS += -lopencv_calib3d246d \
        -lopencv_contrib246d \
        -lopencv_core246d \
        -lopencv_features2d246d \
        #-lopencv_ffmpeg246d \
        -lopencv_flann246d \
        -lopencv_gpu246d \
        -lopencv_highgui246d \
        -lopencv_imgproc246d \
        -lopencv_legacy246d \
        -lopencv_ml246d \
        -lopencv_nonfree246d \
        -lopencv_objdetect246d \
        -lopencv_ocl246d \
        -lopencv_photo246d \
        -lopencv_stitching246d \
        -lopencv_superres246d \
        -lopencv_ts246d \
        -lopencv_video246d \
        -lopencv_videostab246d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_calib3d246 \
        -lopencv_contrib246 \
        -lopencv_core246 \
        -lopencv_features2d246 \
        #-lopencv_ffmpeg246 \
        -lopencv_flann246 \
        -lopencv_gpu246 \
        -lopencv_highgui246 \
        -lopencv_imgproc246 \
        -lopencv_legacy246 \
        -lopencv_ml246 \
        -lopencv_nonfree246 \
        -lopencv_objdetect246 \
        -lopencv_ocl246 \
        -lopencv_photo246 \
        -lopencv_stitching246 \
        -lopencv_superres246 \
        -lopencv_ts246 \
        -lopencv_video246 \
        -lopencv_videostab246
    }

}
click to hide/show revision 2
added webcam brand and model.

capture video from my web cam only shows gray.

trying to capture video from my web cam only shows gray.

Using Using: - Visual Studio 2012 - C++/Qt.C++/Qt. - Logitech QuickCam Ultra Vision

this is what i get when i try to capture the frames: i.imgur.com/x7zYVAX.jpgi.imgur.com/x7zYVAX.jpg the lines you see is my window curtains.

some code:

    qDebug() << "button 0 clicked." << endl;

    //Opens the video device #0.
    cap = new VideoCapture(0);
    if (!cap->isOpened())
    {
        qDebug() << "Cannot open the video file" << endl;
        return;
    }

    cv::Mat srcFrame;
    //read a new frame from video.
    bool bSuccess = cap->read(srcFrame);
    if (!bSuccess)
    {
        qDebug() << "Cannot read a frame from video device." << endl;
        return;
    }

    scene->addPixmap(QPixmap::fromImage(Mat2QImage(srcFrame), Qt::AutoColor));

QImage MainWindow::Mat2QImage(cv::Mat const& src)
{
     cv::Mat temp; // make the same cv::Mat
     cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
     QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
     QImage dest2(dest);
     dest2.detach(); // enforce deep copy
     return dest2;
}

my .pro file:

win32 {

    INCLUDEPATH += C:/opencv/build/include
    LIBS += -LC:/opencv/build/x86/vc11/lib

    CONFIG(debug, debug|release) {
        LIBS += -lopencv_calib3d246d \
        -lopencv_contrib246d \
        -lopencv_core246d \
        -lopencv_features2d246d \
        #-lopencv_ffmpeg246d \
        -lopencv_flann246d \
        -lopencv_gpu246d \
        -lopencv_highgui246d \
        -lopencv_imgproc246d \
        -lopencv_legacy246d \
        -lopencv_ml246d \
        -lopencv_nonfree246d \
        -lopencv_objdetect246d \
        -lopencv_ocl246d \
        -lopencv_photo246d \
        -lopencv_stitching246d \
        -lopencv_superres246d \
        -lopencv_ts246d \
        -lopencv_video246d \
        -lopencv_videostab246d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_calib3d246 \
        -lopencv_contrib246 \
        -lopencv_core246 \
        -lopencv_features2d246 \
        #-lopencv_ffmpeg246 \
        -lopencv_flann246 \
        -lopencv_gpu246 \
        -lopencv_highgui246 \
        -lopencv_imgproc246 \
        -lopencv_legacy246 \
        -lopencv_ml246 \
        -lopencv_nonfree246 \
        -lopencv_objdetect246 \
        -lopencv_ocl246 \
        -lopencv_photo246 \
        -lopencv_stitching246 \
        -lopencv_superres246 \
        -lopencv_ts246 \
        -lopencv_video246 \
        -lopencv_videostab246
    }

}

capture video from my web cam only shows gray.

trying to capture video from my web cam only shows gray.

Using: gray.

Using:
- Visual Studio 2012 - C++/Qt. C++/Qt.
- Logitech QuickCam Ultra Vision




this is what i get when i try to capture the frames: i.imgur.com/x7zYVAX.jpg frames:
i.imgur.com/x7zYVAX.jpg
the lines you see is my window curtains.




some code:

    //Opens the video device #0.
    cap = new VideoCapture(0);
    if (!cap->isOpened())
    {
        qDebug() << "Cannot open the video file" << endl;
        return;
    }

    cv::Mat srcFrame;
    //read a new frame from video.
    bool bSuccess = cap->read(srcFrame);
    if (!bSuccess)
    {
        qDebug() << "Cannot read a frame from video device." << endl;
        return;
    }

    scene->addPixmap(QPixmap::fromImage(Mat2QImage(srcFrame), Qt::AutoColor));

QImage MainWindow::Mat2QImage(cv::Mat const& src)
{
     cv::Mat temp; // make the same cv::Mat
     cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
     QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
     QImage dest2(dest);
     dest2.detach(); // enforce deep copy
     return dest2;
}

my .pro file:

win32 {

    INCLUDEPATH += C:/opencv/build/include
    LIBS += -LC:/opencv/build/x86/vc11/lib

    CONFIG(debug, debug|release) {
        LIBS += -lopencv_calib3d246d \
        -lopencv_contrib246d \
        -lopencv_core246d \
        -lopencv_features2d246d \
        #-lopencv_ffmpeg246d \
        -lopencv_flann246d \
        -lopencv_gpu246d \
        -lopencv_highgui246d \
        -lopencv_imgproc246d \
        -lopencv_legacy246d \
        -lopencv_ml246d \
        -lopencv_nonfree246d \
        -lopencv_objdetect246d \
        -lopencv_ocl246d \
        -lopencv_photo246d \
        -lopencv_stitching246d \
        -lopencv_superres246d \
        -lopencv_ts246d \
        -lopencv_video246d \
        -lopencv_videostab246d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_calib3d246 \
        -lopencv_contrib246 \
        -lopencv_core246 \
        -lopencv_features2d246 \
        #-lopencv_ffmpeg246 \
        -lopencv_flann246 \
        -lopencv_gpu246 \
        -lopencv_highgui246 \
        -lopencv_imgproc246 \
        -lopencv_legacy246 \
        -lopencv_ml246 \
        -lopencv_nonfree246 \
        -lopencv_objdetect246 \
        -lopencv_ocl246 \
        -lopencv_photo246 \
        -lopencv_stitching246 \
        -lopencv_superres246 \
        -lopencv_ts246 \
        -lopencv_video246 \
        -lopencv_videostab246
    }

}
click to hide/show revision 4
retagged

updated 2013-09-30 02:53:52 -0600

berak gravatar image

capture video from my web cam only shows gray.

trying to capture video from my web cam only shows gray.

Using:
- Visual Studio 2012 - C++/Qt.
- Logitech QuickCam Ultra Vision


this is what i get when i try to capture the frames:
i.imgur.com/x7zYVAX.jpg
the lines you see is my window curtains.


some code:

    //Opens the video device #0.
    cap = new VideoCapture(0);
    if (!cap->isOpened())
    {
        qDebug() << "Cannot open the video file" << endl;
        return;
    }

    cv::Mat srcFrame;
    //read a new frame from video.
    bool bSuccess = cap->read(srcFrame);
    if (!bSuccess)
    {
        qDebug() << "Cannot read a frame from video device." << endl;
        return;
    }

    scene->addPixmap(QPixmap::fromImage(Mat2QImage(srcFrame), Qt::AutoColor));

QImage MainWindow::Mat2QImage(cv::Mat const& src)
{
     cv::Mat temp; // make the same cv::Mat
     cvtColor(src, temp,CV_BGR2RGB); // cvtColor Makes a copt, that what i need
     QImage dest((uchar*) temp.data, temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
     QImage dest2(dest);
     dest2.detach(); // enforce deep copy
     return dest2;
}

my .pro file:

win32 {

    INCLUDEPATH += C:/opencv/build/include
    LIBS += -LC:/opencv/build/x86/vc11/lib

    CONFIG(debug, debug|release) {
        LIBS += -lopencv_calib3d246d \
        -lopencv_contrib246d \
        -lopencv_core246d \
        -lopencv_features2d246d \
        #-lopencv_ffmpeg246d \
        -lopencv_flann246d \
        -lopencv_gpu246d \
        -lopencv_highgui246d \
        -lopencv_imgproc246d \
        -lopencv_legacy246d \
        -lopencv_ml246d \
        -lopencv_nonfree246d \
        -lopencv_objdetect246d \
        -lopencv_ocl246d \
        -lopencv_photo246d \
        -lopencv_stitching246d \
        -lopencv_superres246d \
        -lopencv_ts246d \
        -lopencv_video246d \
        -lopencv_videostab246d
    }
    CONFIG(release, debug|release) {
        LIBS += -lopencv_calib3d246 \
        -lopencv_contrib246 \
        -lopencv_core246 \
        -lopencv_features2d246 \
        #-lopencv_ffmpeg246 \
        -lopencv_flann246 \
        -lopencv_gpu246 \
        -lopencv_highgui246 \
        -lopencv_imgproc246 \
        -lopencv_legacy246 \
        -lopencv_ml246 \
        -lopencv_nonfree246 \
        -lopencv_objdetect246 \
        -lopencv_ocl246 \
        -lopencv_photo246 \
        -lopencv_stitching246 \
        -lopencv_superres246 \
        -lopencv_ts246 \
        -lopencv_video246 \
        -lopencv_videostab246
    }

}