SHARE
TWEET

Untitled

a guest Feb 27th, 2020 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/imgproc.hpp>
  4.  
  5. int main()
  6. {  
  7.     std::string coinsPath = "C:\\Users\\Nonko\\Desktop\\water_coins.jpg";
  8.  
  9.     cv::Mat coinsImage = cv::imread(coinsPath);
  10.     cv::imshow("coins", coinsImage);
  11.  
  12.     cv::Mat coinImageGray;
  13.     cv::cvtColor(coinsImage, coinImageGray, cv::COLOR_BGR2GRAY);
  14.     cv::imshow("coinsGray", coinImageGray);
  15.  
  16.  
  17.     cv::Mat coinsThreshold;
  18.     cv::threshold(coinImageGray, coinsThreshold, 140, 255, cv::THRESH_BINARY_INV);
  19.     cv::imshow("coinsThresh", coinsThreshold);
  20.  
  21.  
  22.     cv::Mat coinsErode;
  23.     cv::erode(coinsThreshold, coinsErode, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(9, 9)));
  24.     cv::erode(coinsErode, coinsErode, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(9, 9)));
  25.     cv::erode(coinsErode, coinsErode, cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(9, 9)));
  26.     cv::imshow("coinsErode", coinsErode);
  27.  
  28.     std::vector<std::vector<cv::Point>> coinsContours;
  29.     std::vector<cv::Vec4i> coinsHierarchy;
  30.    
  31.     cv::findContours(coinsErode, coinsContours, coinsHierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
  32.     cv::Mat coinsContoursMat = cv::Mat::zeros(coinsErode.size(), CV_8UC3);
  33.  
  34.     for (int i = 0; i < coinsContours.size(); i++)
  35.     {
  36.         cv::drawContours(coinsContoursMat, coinsContours, i, cv::Scalar(255, 255, 255));
  37.     }
  38.  
  39.     cv::imshow("coinsContoursMat", coinsContoursMat);
  40.  
  41.     cv::Mat coinsConvolution = cv::Mat::ones(3, 3, CV_32F) / 9.f;
  42.     cv::Mat coinsConvolutionMat;
  43.     cv::filter2D(coinImageGray, coinsConvolutionMat, -1, coinsConvolution);
  44.     cv::imshow("coinsConvolutionMat", coinsConvolutionMat);
  45.    
  46.     cv::waitKey();
  47.     return 0;
  48.    
  49.     cv::Mat pictureFrame;
  50.     std::string string = "C:\\Users\\Nonko\\Desktop\\Annotation 2020-02-20 153704.png";
  51.     pictureFrame = cv::imread(string);
  52.     imshow("viii", pictureFrame);
  53.    
  54.    
  55.     cv::Mat textTextFrame = cv::Mat(400, 600, CV_8UC3, cv::Scalar(0, 0, 0));
  56.     putText(textTextFrame, "asdasdasdasdTEXT", cv::Point(100, 100), cv::FONT_HERSHEY_PLAIN, 1.0, cv::Scalar(0, 0, 0));
  57.     imshow("test", textTextFrame);
  58.     cv::waitKey();
  59.  
  60.     cv::VideoCapture cap(0);
  61.     cv::Mat cameraCaptureFrame;
  62.     cv::Mat cameraCaptureFrameGray;
  63.     cv::Mat cameraCaptureFrameGrayEdges;
  64.  
  65.     for (;;)
  66.     {
  67.         cap >> cameraCaptureFrame;
  68.  
  69.         cv::imshow("camera", cameraCaptureFrame);
  70.  
  71.         cv::cvtColor(cameraCaptureFrame, cameraCaptureFrameGray, cv::COLOR_BGR2GRAY);
  72.  
  73.         cv::adaptiveThreshold(cameraCaptureFrameGray, cameraCaptureFrameGray, 100, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 11, 0);
  74.  
  75.         cv::Canny(cameraCaptureFrameGray, cameraCaptureFrameGrayEdges, 1, 2);
  76.        
  77.         cv::imshow("grey", cameraCaptureFrameGray);
  78.         cv::imshow("greyedges", cameraCaptureFrameGrayEdges);
  79.        
  80.         if(cv::waitKey(30) >= 0)
  81.         {
  82.             break;
  83.         }
  84.     }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top