1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| #include "videoprocessor.h"
void draw(const cv::Mat& img, cv::Mat& out) {
img.copyTo(out); cv::circle(out, cv::Point(100,100),5,cv::Scalar(255,0,0),2); }
void canny(cv::Mat& img, cv::Mat& out) {
if (img.channels()==3) cv::cvtColor(img,out,cv::COLOR_BGR2GRAY); cv::Canny(out,out,100,200); cv::threshold(out,out,128,255,cv::THRESH_BINARY_INV); }
int main() { cv::VideoCapture capture("bike.avi");
if (!capture.isOpened()) return 1;
double rate= capture.get(cv::CAP_PROP_FPS); std::cout << "Frame rate: " << rate << "fps" << std::endl;
bool stop(false); cv::Mat frame; cv::namedWindow("Extracted Frame");
int delay= 1000/rate; long long i=0; std::string b="bike"; std::string ext=".bmp"; while (!stop) {
if (!capture.read(frame)) break;
cv::imshow("Extracted Frame",frame);
std::string name(b); std::ostringstream ss; ss << std::setfill('0') << std::setw(3) << i; name+= ss.str(); i++; name+=ext;
std::cout << name <<std::endl; cv::Mat test;
if (cv::waitKey(delay)>=0) stop= true; }
capture.release();
cv::waitKey();
VideoProcessor processor;
processor.setInput("bike.avi");
processor.displayInput("Input Video"); processor.displayOutput("Output Video");
processor.setDelay(1000./processor.getFrameRate());
processor.setFrameProcessor(canny);
processor.setOutput("bikeCanny.avi",-1,15);
processor.stopAtFrameNo(51);
processor.run();
cv::waitKey();
return 0; }
|