本文整理汇总了C++中VideoWriter::get方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoWriter::get方法的具体用法?C++ VideoWriter::get怎么用?C++ VideoWriter::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VideoWriter
的用法示例。
在下文中一共展示了VideoWriter::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
int frame_num = 0;
int non_decode_frame =0;
int count = 1, idx =0;
int frame_pos =0;
int p = 0;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
MOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
std::cout<<"Video File "<<argv[1]<<std::endl;
// cv::VideoCapture input_video(argv[1]);
cv::VideoCapture cap("IM-4559-%04d.png");
namedWindow("My_Win",1);
cvSetMouseCallback("My_Win", mouse_click, 0);
sleep(1);
while(cap.grab())
{
cap_img.release();
p++;
if(cap.retrieve(cap_img))
{
imshow("My_Win", cap_img);
if(!got_roi)
{
//Wait here till user select the desire ROI
waitKey(0);
}
else
{
std::cout<<"Got ROI disp prev and curr image"<<std::endl;
std::cout<<"PT1"<<pt1.x<<" "<<pt1.y<<std::endl;
std::cout<<"PT2"<<pt2.x<<" "<<pt2.y<<std::endl;
if(vw.isOpened()){
std::cout<<"VW Opened\n";
}
Mat curr_img_t1;
Mat roi2(cap_img,Rect(pt1, pt2));
Mat curr_imgT = roi2.clone();
MOG2->apply(curr_imgT, fgMaskMOG2);
//get the frame number and write it on the current frame
stringstream ss;
rectangle(curr_imgT, cv::Point(10, 2), cv::Point(100,20),cv::Scalar(255,255,255), -1);
ss << vw.get(CAP_PROP_POS_FRAMES);
string frameNumberString = ss.str();
putText(curr_imgT, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
float morph_size = 2;
Mat grad;
Mat canny_output;
Mat thrld;
Mat element = getStructuringElement(MORPH_RECT,Size(2*morph_size+1,2*morph_size+1), Point(morph_size,morph_size));
morphologyEx(fgMaskMOG2,grad,MORPH_GRADIENT,element, Point(-1,-1),1);
Canny(curr_imgT, canny_output, thresh,thresh*2 , 3);
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
namedWindow( "Contours", WINDOW_AUTOSIZE );
imshow( "Contours", drawing );
threshold(grad,thrld,200,0,3);
char file_name[100];
sprintf(file_name, "final%d.png",p);
//show the current frame and the fg masks
imwrite(file_name,drawing);
imshow("background", fgMaskMOG2);
waitKey(30);
}
}
std::cout<<p<<std::endl;
}
vw.release();
}