本文整理汇总了C++中cv::VideoWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoWriter::write方法的具体用法?C++ VideoWriter::write怎么用?C++ VideoWriter::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::VideoWriter
的用法示例。
在下文中一共展示了VideoWriter::write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void Tracker2D::writeToVideo(cv::VideoWriter & writer)
{
cv::Mat dispImage;
drawTrackers(dispImage);
writer.write(dispImage);
}
示例2: operator
void operator()(const cv::Mat& image,bool record)
{
// no image no fun
if (image.empty()) return;
int cF = currentFrame ? 1 : 0;
int pF = currentFrame ? 0 : 1;
// resize the image
cv::resize(image,frames[cF],cv::Size(image.cols*scale,image.rows*scale),0,0,cv::INTER_LINEAR);
std::cout << "Current: " << cF << " Previous: " << pF << std::endl;
std::cout << "Image " << image.size() << " c:" << image.channels() << " > " << frames[cF].size() << std::endl;
if (record && !output.isOpened())
{
// fourcc
int fourCC = FourCC<'X','V','I','D'>::value;
// set framerate to 1fps - easier to check in a standard video player
if (output.open("flow.avi",fourCC,25,frames[cF].size(),false))
{
std::cout << "capture file opened" << std::endl;
}
}
// make a copy for the initial frame
if (frames[pF].empty())
frames[cF].copyTo(frames[pF]);
if (!flow.empty())
flow = cv::Mat::zeros(flow.size(),flow.type());
// calculate dense optical flow
cv::calcOpticalFlowFarneback(frames[pF],frames[cF],flow,.5,2,8,3,7,1.5,0);
// we can't draw into the frame!
cv::Mat outImg = frames[cF].clone();
drawOptFlowMap(flow,outImg,8,cv::Scalar::all(255));
cv::imshow("Flow",outImg);
// flip the buffers
currentFrame = !currentFrame;
// record the frame
if (record && output.isOpened())
output.write(outImg);
}
示例3: imgproc
//.........这里部分代码省略.........
findContours(src, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE);
//printf("Num contours: %lu\n", contours.size());
std::vector<double> contour_area, contour_arclength;
contour_area.resize(contours.size());
contour_arclength.resize(contours.size());
std::vector<unsigned int> circle_index;
for(unsigned int idx = 0; idx < contours.size(); idx++)
{
if(contours[idx].size() > 25)
{
cv::Mat contour(contours[idx]);
contour_area[idx] = contourArea(contour);
if(contour_area[idx] > 50)
{
contour_arclength[idx] = arcLength(contour,true);
float q = 4*M_PI*contour_area[idx] /
(contour_arclength[idx]*contour_arclength[idx]);
if(q > 0.8f)
{
circle_index.push_back(idx);
//printf("isoperimetric quotient: %f\n", q);
//Scalar color( rand()&255, rand()&255, rand()&255 );
//drawContours(contours_dark, contours, idx, color, 1, 8);
}
}
}
}
std::list<Circle> circles;
for(unsigned int i = 0; i < circle_index.size(); i++)
{
Circle c;
cv::Moments moment = moments(contours[circle_index[i]]);
float inv_m00 = 1./moment.m00;
c.center = cv::Point2f(moment.m10*inv_m00, moment.m01*inv_m00);
c.radius = (sqrtf(contour_area[circle_index[i]]/M_PI) + contour_arclength[circle_index[i]]/(2*M_PI))/2.0f;
circles.push_back(c);
}
// Get the circles with centers close to each other
std::vector<std::list<Circle> > filtered_circles;
std::list<Circle>::iterator it = circles.begin();
unsigned int max_length = 0;
while(it != circles.end())
{
std::list<Circle> c;
c.push_back(*it);
cv::Point c1 = it->center;
std::list<Circle>::iterator it2 = it;
it2++;
while(it2 != circles.end())
{
cv::Point c2 = it2->center;
std::list<Circle>::iterator it3 = it2;
it2++;
if(hypotf(c2.x - c1.x, c2.y - c1.y) < 10)
{
c.push_back(*it3);
circles.erase(it3);
}
}
unsigned int length_c = c.size();
if(length_c > 1 && length_c > max_length)
{
max_length = length_c;
filtered_circles.push_back(c);
}
it2 = it;
it++;
circles.erase(it2);
}
if(filtered_circles.size() > 0)
{
Circle target_circle;
target_circle.radius = std::numeric_limits<float>::max();
for(it = filtered_circles.back().begin(); it != filtered_circles.back().end(); it++)
{
//printf("circle: c: %f, %f, r: %f\n", it->center.x, it->center.y, it->radius);
if(it->radius < target_circle.radius)
{
target_circle.radius = it->radius;
target_circle.center = it->center;
}
}
circle(color_src, cv::Point(target_circle.center.x, target_circle.center.y), target_circle.radius, cv::Scalar(0,0,255), 2);
printf("target: c: %f, %f, r: %f\n", target_circle.center.x, target_circle.center.y, target_circle.radius);
}
#if defined(CAPTURE_VIDEO)
static cv::VideoWriter video_writer("output.mp4", CV_FOURCC('M','J','P','G'), 20, cv::Size(width, height));
video_writer.write(color_src);
#endif
imshow("Target", color_src);
cv::waitKey(1);
}