In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to achieve C++ OpenCV marker detection". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to achieve C++ OpenCV marker detection" can help you solve the problem.
The effect is as follows:
1. Import the original image:
two。 Intercept ROI
3. Adaptive thresholding and Canny Edge extraction
4. The closed operation is carried out, then the contour is detected, the area of the point set is calculated, and the miscellaneous points are removed by the area threshold.
5. Detect the contour again and fit the ellipse
The code is as follows:
# include # define scale 2 define cannythreshold 80typedef struct / image scaling factor # define cannythreshold 80typedef struct _ ROIStruct {cv::Point2d ROIPoint; cv::Mat ROIImage;} ROIStruct;ROIStruct getROI (cv::Mat src,bool flag = false) {ROIStruct ROI_Struct; cv::Rect2d ROIrect = selectROI (src); ROI_Struct.ROIPoint = ROIrect.tl () / / get the point ROI_Struct.ROIImage = src (ROIrect) in the upper left corner of the ROI region; if (flag = = true) {cv::imshow ("ROI", ROI_Struct.ROIImage);} return ROI_Struct;} int main () {cv::Mat srcImage = cv::imread ("7.jpg") / / read cv::resize (srcImage, srcImage, cv::Size (srcImage.cols / scale, srcImage.rows / scale)); / / zoom the image, otherwise the original image will display ROIStruct ROI = getROI (srcImage) in ROI; / / Select ROI region cv::Mat DetectImage, thresholdImage; ROI.ROIImage.copyTo (DetectImage); cv::imshow ("ROI", DetectImage) Cv::cvtColor (DetectImage, thresholdImage, CV_RGB2GRAY); cv::adaptiveThreshold (thresholdImage, thresholdImage, 255,255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY,11,35); / / Adaptive threshold cv::Canny (thresholdImage, thresholdImage, cannythreshold, cannythreshold * 3,3); cv::imshow ("thresholdImage", thresholdImage); std::vector contours1; std::vector hierarchy1 Cv::Mat element = cv::getStructuringElement (cv::MORPH_ELLIPSE, cv::Size (3,3)); cv::morphologyEx (thresholdImage, thresholdImage, cv::MORPH_CLOSE, element,cv::Point (- 1jjimi 1), 2); cv::Mat findImage = cv::Mat::zeros (thresholdImage.size (), CV_8UC3); cv::findContours (thresholdImage, contours1, hierarchy1,CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE) For (int I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.