Ask Your Question
0

Pixcel values in 2 different frames always show to be the same.

asked 2013-11-19 18:28:35 -0600

97Viper gravatar image

updated 2013-11-19 23:39:10 -0600

Haris gravatar image

I capture 2 different frames yet when I try to compare pixcel values between the 2 frames, they appear to be identical. I am probable misusing Vec3b. Please help an obvious novice. Thanks.

// November 11 2013 Capture and display values of 2 full color frames
#include "stdafx.h"
#include "iostream"
#include "opencv2/core/types_c.h"
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;   

    namedWindow("frame",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get frame from camera

        imshow("frame", frame);

        if(waitKey(1000) >= 0) break;

        Mat frame1;
        cap >> frame1; // get frame1 from camera    

        imshow("frame1", frame1);

        if(waitKey(1000) >= 0) break;


        for(int i=0; i<480; i++)
            for(int j=0; j<640; j++)
                {cv::Vec3b tmp1 = frame1.at<cv::Vec3b>(i,j);std::cout << "i= "<<i<<" j= "<<j<< " frame1  "<<(int)tmp1(0) << " " << (int)tmp1(1) << " " << (int)tmp1(2)<< std::endl;
                 cv::Vec3b tmp = frame.at<cv::Vec3b>(i,j);std::cout << "          frame   "<<(int)tmp(0) << " " << (int)tmp(1) << " " << (int)tmp(2)<< std::endl;

        if(waitKey(1000) >= 0) break;
        }

        if(waitKey(1000) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-11-20 00:39:09 -0600

Michael Burdinov gravatar image

As far as I remember, >> operator creates matrix that points to place where last grabbed image is stored. It doesn't perform real copy of data of image. And next grabbed image will be stored in the same place, since it is not storing all the previous frames unless you did that manually. So by calling 'cap >> frame1;' you changed contents of frame as well. Now both frame and frame1 points to the same place. So course they will be the same. You should use functions like clone() or copyTo() if you want to store the your frame somewhere else.

edit flag offensive delete link more

Comments

Thanks. Was hoping I didn't have to go from picture frame to matrix and back to picture frame to do pixcel operations.

97Viper gravatar image97Viper ( 2013-11-20 13:35:44 -0600 )edit

Question Tools

Stats

Asked: 2013-11-19 18:28:35 -0600

Seen: 246 times

Last updated: Nov 20 '13