Subtracting pixels of 2 different Mat using Vec3b & always get 0 diff.

asked 2014-02-10 19:56:02 -0600

97Viper gravatar image

include <iostream>

include <opencv2 opencv.hpp="">

include <opencv2 core="" types_c.h="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 objdetect="" objdetect.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <iostream>

include <stdio.h>

using namespace cv; using namespace std; int R; int B; int G; int R1; int B1; int G1; int Total;

int main() { CvCapture* capture = 0; VideoCapture cap(0); // open the default camera if (!cap.isOpened()) // check if we succeeded return -1;

Mat frame1;
Mat frame2;
Mat frame1copy;
Mat frame2copy;

for (;;)
{
    cap >> frame1; // get a frame from camera

    frame1.copyTo(frame1copy);

    imshow("frame1copy", frame1copy);

    if (waitKey(1000) >= 0) break;// Break with Esc

    cap >> frame2; // get a new frame from camera
    frame2.copyTo(frame2copy);

    imshow("frame2copy", frame2copy);

    if (waitKey(1000) >= 0) break;// Break with Esc


    for (int i = 0; i < 480; i++)
    for (int j = 0; j < 640; j++)
    {
        cv::Vec3b tmp = frame1copy.at<cv::Vec3b>(i, j);
        B = (int)tmp(0);
        G = (int)tmp(1);
        R = (int)tmp(2);

        cv::Vec3b tmp1 = frame2copy.at<cv::Vec3b>(i, j);
        B1 = (int)tmp(0);
        G1 = (int)tmp(1);
        R1 = (int)tmp(2);

        Total = R + B + G-R1-B1-G1;
        std::cout << "Total=  "<< Total <<std::endl;

    }
}

return 0;

}

edit retag flag offensive close merge delete