#include #include #include #include #include #include //compiled with g++ -Wall -c "%f" -I/usr/local/include/opencv4 //built with: g++ -Wall -o "%e" "%f" `pkg-config --cflags --libs opencv4` using namespace cv; using namespace std; /// Function header void thresh_callback(int, void* ); void vectorOutput( vector>, vector hierarchy); void contour2svg(vector> contours); void svgHeader(); void polyline(); void svgFooter(); Mat src; Mat src_gray; int thresh = 50; int max_thresh = 215; RNG rng(12345); //random number generator /** @function main */ int main( int argc, char** argv ){ VideoCapture cap; // open the default camera, use something different from 0 otherwise; if(!cap.open(0)) return 0; // Create mat with alpha channel Mat mat(800, 800, CV_8UC4); for(;;){ Mat frame; cap >> frame; src = frame; /// Convert image to gray and blur it cv::cvtColor(src, src_gray, COLOR_BGRA2GRAY, 0); blur( src_gray, src_gray, Size(3,3) ); thresh_callback( 0 , 0 ); if( waitKey(1) == 113 ) break; // stop capturing by pressing q } return(0); } /*******************/ /* */ /* FUNCTIONS */ /* */ /*******************/ void contour2svg(){ svgHeader(); polyline(); svgFooter(); } void svgHeader(){ cout<< "" << endl; }; void polyline(){ //actual function might be: cout points(Cordinates) cout << "" << endl; } void svgFooter(){ cout << "" << endl; }; void vectorOutput( vector > contours, int i){ for(auto vec: contours){ cout << vec << "\n"; } }; /** @function thresh_callback */ void thresh_callback(int, void* ){ Mat canny_output; vector > contours; vector hierarchy; /// Detect edges using canny Canny( src_gray, canny_output, thresh, thresh*2, 3 ); /// Find contours findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point() ); /// Draw contours /*void cv::drawContours ( InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar & color, int thickness = 1, //can be a FLOAT int lineType = LINE_8, InputArray hierarchy = noArray(), int maxLevel = INT_MAX, Point offset = Point() //can be Point() or Point(x,y) cordinates )*/ Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 ); for(unsigned int i = 0; i< contours.size(); i++ ){ //Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); Scalar color = Scalar( 0, 0,255 ); //BGR, set to red drawContours( drawing, contours, i, color, 0.1, 8, hierarchy, 1, Point(0,0) ); //vectorOutput( contours, i); } sleep(0.25); //slow down there flashy flashy /// Show in a window //createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback ); namedWindow("Name", 1); //what does 1 mean? cv::imshow("Name", drawing); }