Khi connect internet thi em extract frame thanh cong. Nhung khi disconnect internet thi frame no data. Anh chi giup e : lam nhu the nao de khi reconnect thi extract frame duoc ?
#include "opencv2/opencv.hpp"
#include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
using namespace cv;
void extractFromStream(VideoCapture cap)
{
int id=0;
while(1)
{
Mat img;
bool bSuccess = cap.read(img);
if(!bSuccess)
{
cout<<"No frame\n";
waitKey();
}
id++;
char filename[100];
strcpy(filename, "/home/dieuninh/Desktop/a/i_");
char frame_id[30];
sprintf(frame_id,"%d",id);
strcat(filename, frame_id);
strcat(filename, ".jpg");
cout<<endl<<filename<<endl;
imwrite( filename, img );
if(cv::waitKey(1) ==27) break;
}
}
int main() {
string stream="http://4co2.vp9.tv/chn/VTT4/v.m3u8";
VideoCapture cap;
cap.open(stream);
bool success=cap.isOpened();
if( !success){
cout << "Cannot open the video file" << endl;
return -1;
}
cout<<"OKKKKKKKKKKKK";
extractFromStream(cap);
waitKey(0);
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?