Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LaurentBerger/56e6955fbc991da773fadadb75c081c7 to your computer and use it in GitHub Desktop.
Save LaurentBerger/56e6955fbc991da773fadadb75c081c7 to your computer and use it in GitHub Desktop.
videoFFMPEG.cpp
void main(void)
{
// vector<int> pos = { 1 * 50, 2 * 50,3 * 50,5 * 50,7 * 50,11 * 50,13 * 50,17 * 50,19 * 50,23 * 50,29 * 50,31 * 50,37 * 50,41 * 50,43 * 50 };
vector<int> pos = { 1 * 50, 2 * 50,3 * 50,5 * 50,7 * 50,11 * 50,13 * 50 };
vector<Mat> frameSelec;
VideoCapture video("malfunction_small.mp4");
if (!video.isOpened())
{
cout << "Video introuvable";
return ;
}
Mat frameVideo;
int fourcc = video.get(CAP_PROP_FOURCC);
string fourcc_str = format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
cout << "CAP_PROP_FOURCC: " << fourcc_str << endl;
double minV[1], maxV[1];
vector<Mat> frameFFMPEG;
for (int j = 0, i = 0; i < pos[pos.size()-1]+5; i++)
{
video >> frameVideo;
String s= format("F:/ffmpeg-20150605-git-7be0f48-win64-shared/bin/image%04d.png", i+1);
Mat d,regffmpeg=imread(s,IMREAD_COLOR);
frameFFMPEG.push_back(regffmpeg.clone());
subtract(frameVideo, regffmpeg, d, noArray(), CV_16S);
d = d.reshape(1);
minMaxLoc(d, minV, maxV);
if (j<pos.size() && i == pos[j])
{
frameSelec.push_back(frameVideo.clone());
j++;
}
}
video.set(CAP_PROP_POS_FRAMES, 0);
for (int j = 0; j < pos.size(); j++)
{
cout<<"**************************************\n";
video.set(CAP_PROP_POS_FRAMES, pos[j] - 3);
for (int kk = 0; kk < 6; kk++)
{
video >> frameVideo;
Mat d;
imshow("flu", frameVideo);
imshow("fpo", frameSelec[j]);
subtract(frameVideo, frameSelec[j], d, noArray(), CV_16S);
d = d.reshape(1);
minMaxLoc(d, minV, maxV);
if (abs(minV[0]) + abs(maxV[0]) == 0)
{
cout << "Min for frame " << pos[j] - 3 + kk << "expected " << pos[j] << " \t" << minV[0] << "\t" << maxV[0] << "\t";
cout << "\n";
}
if (kk == 3)
{
cout << "error for frame " << pos[j] - 3 + kk << " \t" << minV[0] << "\t" << maxV[0] << "\t";
cout << "\n";
}
subtract(frameVideo, frameFFMPEG[pos[j]], d, noArray(), CV_16S);
d = d.reshape(1);
minMaxLoc(d, minV, maxV);
cout << "For frameFFMPEG " << pos[j] - 3 + kk << " \t" << minV[0] << "\t" << maxV[0] << "\n";
d = abs(d);
d.convertTo(d, CV_8U);
d = d.reshape(3, frameVideo.rows);
imshow("diff", d);
}
waitKey(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment