Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

video frame is different frome imgs?

int main(int argc, char** argv) { if (argc != 2) { help(argv); return 1; } std::string arg = argv[1]; VideoCapture capture(arg); if (!capture.isOpened()){ capture.open(atoi(arg.c_str())); } if (!capture.isOpened()) { cerr << "Failed to open a video device or video file!\n" << endl; help(argv); return 1; }

char filename[200];
Mat frame1;
Mat frame2;
Mat frame3;
Mat frame4;

capture >> frame1;
sprintf(filename,"frame%.3d.jpg",1);
imwrite(filename,frame1);
frame3 = imread(filename);

capture.set(CV_CAP_PROP_POS_FRAMES, 100);

capture >> frame2;
sprintf(filename,"frame%.3d.jpg",2);
imwrite(filename,frame2);
frame4 = imread(filename);

cout << (double)cmpHistOfHSV(frame1, frame2) << endl;
cout << (double)partOfCmpHist(frame1, frame2) << endl;

cout << cmpHistOfHSV(frame3, frame4) << endl;
cout << partOfCmpHist(frame3, frame4) << endl;
return 0;

}

the output: 0 0 4074.85 6790.25 why, the video frame is different the img?

video frame is different frome imgs?

int main(int argc, char** argv) { if (argc != 2) { help(argv); return 1; } std::string arg = argv[1]; VideoCapture capture(arg); if (!capture.isOpened()){ capture.open(atoi(arg.c_str())); } if (!capture.isOpened()) { cerr << "Failed to open a video device or video file!\n" << endl; help(argv); return 1; }

char filename[200];
Mat frame1;
Mat frame2;
Mat frame3;
Mat frame4;

capture >> frame1;
sprintf(filename,"frame%.3d.jpg",1);
imwrite(filename,frame1);
frame3 = imread(filename);

capture.set(CV_CAP_PROP_POS_FRAMES, 100);

capture >> frame2;
sprintf(filename,"frame%.3d.jpg",2);
imwrite(filename,frame2);
frame4 = imread(filename);

cout << (double)cmpHistOfHSV(frame1, frame2) << endl;
cout << (double)partOfCmpHist(frame1, frame2) << endl;

cout << cmpHistOfHSV(frame3, frame4) << endl;
cout << partOfCmpHist(frame3, frame4) << endl;
return 0;

}

the output: 0 0 4074.85 6790.25 why, the video frame is different the img?

video frame is different frome imgs?

int main(int argc, char** argv)
{
if (argc != 2) {
help(argv);
return 1;
}
std::string arg = argv[1];
VideoCapture capture(arg);
if (!capture.isOpened()){
capture.open(atoi(arg.c_str()));
}
if (!capture.isOpened()) {
cerr << "Failed to open a video device or video file!\n" << endl;
help(argv);
return 1;
}

}
char filename[200];
 Mat frame1;
 Mat frame2;
 Mat frame3;
 Mat frame4;
 capture >> frame1;
 sprintf(filename,"frame%.3d.jpg",1);
 imwrite(filename,frame1);
 frame3 = imread(filename);
 capture.set(CV_CAP_PROP_POS_FRAMES, 100);
 capture >> frame2;
 sprintf(filename,"frame%.3d.jpg",2);
 imwrite(filename,frame2);
 frame4 = imread(filename);
 cout << (double)cmpHistOfHSV(frame1, frame2) << endl;
 cout << (double)partOfCmpHist(frame1, frame2) << endl;
 cout << cmpHistOfHSV(frame3, frame4) << endl;
 cout << partOfCmpHist(frame3, frame4) << endl;
 return 0;
}

}the output:

the output:

0
0
4074.85
6790.25

why, the video frame is different the img?

video frame is different frome imgs?

int main(int argc, char** argv)
{
    if (argc != 2) {
    help(argv);
    return 1;
    }
    std::string arg = argv[1];
    VideoCapture capture(arg); 
    if (!capture.isOpened()){ 
    capture.open(atoi(arg.c_str()));
    }
    if (!capture.isOpened()) {
    cerr << "Failed to open a video device or video file!\n" << endl;
    help(argv);
    return 1;
    }

    char filename[200];
    Mat frame1;
    Mat frame2;
    Mat frame3;
    Mat frame4;

    capture >> frame1;
    sprintf(filename,"frame%.3d.jpg",1);
    imwrite(filename,frame1);
    frame3 = imread(filename);

    capture.set(CV_CAP_PROP_POS_FRAMES, 100);

    capture >> frame2;
    sprintf(filename,"frame%.3d.jpg",2);
    imwrite(filename,frame2);
    frame4 = imread(filename);

    cout << (double)cmpHistOfHSV(frame1, frame2) << endl;
    cout << (double)partOfCmpHist(frame1, frame2) << endl;

    cout << cmpHistOfHSV(frame3, frame4) << endl;
    cout << partOfCmpHist(frame3, frame4) << endl;
    return 0;
}

the output:

0
0
4074.85
6790.25

why, the video frame is different the img?

Appendix:

double cmpHistOfHSV(Mat src_base1, Mat src_base2) { const int HL_RANGE = 0; const int HR_RANGE = 256; const int SL_RANGE = 0; const int SR_RANGE = 180;

const int H_BINS = 12;//50
const int S_BINS = 6;//60

Mat hsv_base1, hsv_base2;

// Convert to HSV
cvtColor(src_base1, hsv_base1, CV_BGR2HSV);
cvtColor(src_base2, hsv_base2, CV_BGR2HSV);


//30 bins for Hue, 32 for Saturation
int h_bins = H_BINS;
int s_bins = S_BINS;
int histSize[] = {h_bins, s_bins};

//hue varies from 0 to 256, saturation from 0 to 180
float h_ranges[] = {HL_RANGE, HR_RANGE};
float s_ranges[] = {SL_RANGE, SR_RANGE};
const float *ranges[] = {h_ranges, s_ranges};

//Use the 0th and 1th channels
int channels[] = {0, 1};

//Histogram
MatND hist_base1;
MatND hist_base2;

//Calculate the histogram for HSV images
calcHist(&hsv_base1, 1, channels, Mat(), hist_base1, 2, histSize, ranges, true, false);
normalize(hist_base1, hist_base1, 0, 1, NORM_MINMAX, -1, Mat());

calcHist(&hsv_base2, 1, channels, Mat(), hist_base2, 2, histSize, ranges, true, false);
normalize(hist_base2, hist_base2, 0, 1, NORM_MINMAX, -1, Mat());

double base_base = compareHist(hist_base1, hist_base2, 1);
return base_base;

}

video frame is different frome imgs?

int main(int argc, char** argv)
{
    if (argc != 2) {
    help(argv);
    return 1;
    }
    std::string arg = argv[1];
    VideoCapture capture(arg); 
    if (!capture.isOpened()){ 
    capture.open(atoi(arg.c_str()));
    }
    if (!capture.isOpened()) {
    cerr << "Failed to open a video device or video file!\n" << endl;
    help(argv);
    return 1;
    }

    char filename[200];
    Mat frame1;
    Mat frame2;
    Mat frame3;
    Mat frame4;

    capture >> frame1;
    sprintf(filename,"frame%.3d.jpg",1);
    imwrite(filename,frame1);
    frame3 = imread(filename);

    capture.set(CV_CAP_PROP_POS_FRAMES, 100);

    capture >> frame2;
    sprintf(filename,"frame%.3d.jpg",2);
    imwrite(filename,frame2);
    frame4 = imread(filename);

    cout << (double)cmpHistOfHSV(frame1, frame2) << endl;
    cout << (double)partOfCmpHist(frame1, frame2) << endl;

    cout << cmpHistOfHSV(frame3, frame4) << endl;
    cout << partOfCmpHist(frame3, frame4) << endl;
    return 0;
}

the output:

0
0
4074.85
6790.25

why, the video frame is different the img?

Appendix:

double cmpHistOfHSV(Mat src_base1, Mat src_base2)
{
const int HL_RANGE = 0;
const int HR_RANGE = 256;
const int SL_RANGE = 0;
const int SR_RANGE = 180;

180;
const int H_BINS = 12;//50
 const int S_BINS = 6;//60
 Mat hsv_base1, hsv_base2;
 // Convert to HSV
 cvtColor(src_base1, hsv_base1, CV_BGR2HSV);
 cvtColor(src_base2, hsv_base2, CV_BGR2HSV);
 //30 bins for Hue, 32 for Saturation
 int h_bins = H_BINS;
 int s_bins = S_BINS;
 int histSize[] = {h_bins, s_bins};
 //hue varies from 0 to 256, saturation from 0 to 180
 float h_ranges[] = {HL_RANGE, HR_RANGE};
 float s_ranges[] = {SL_RANGE, SR_RANGE};
 const float *ranges[] = {h_ranges, s_ranges};
 //Use the 0th and 1th channels
 int channels[] = {0, 1};
 //Histogram
 MatND hist_base1;
 MatND hist_base2;
 //Calculate the histogram for HSV images
 calcHist(&hsv_base1, 1, channels, Mat(), hist_base1, 2, histSize, ranges, true, false);
 normalize(hist_base1, hist_base1, 0, 1, NORM_MINMAX, -1, Mat());
 calcHist(&hsv_base2, 1, channels, Mat(), hist_base2, 2, histSize, ranges, true, false);
 normalize(hist_base2, hist_base2, 0, 1, NORM_MINMAX, -1, Mat());
 double base_base = compareHist(hist_base1, hist_base2, 1);
 return base_base;
}

}