Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Don't read my rectangle

$
0
0
I adapted this code to read the white rectangle with the word 23-1965 But, it does not detect it sees a lot of other side dishes, but not what interests me. Who tells me where I'm wrong? Also attach the image to be processed![image description](/upfiles/14551166652131814.jpg) /** * Simple shape detector program. * It loads an image and tries to find simple shapes (rectangle, triangle, circle, etc) in it. * This program is a modified version of `squares.cpp` found in the OpenCV sample dir. */ #include #include #include #include using namespace std; /** * Helper function to find a cosine of angle between vectors * from pt0->pt1 and pt0->pt2 */ static double angle(cv::Point pt1, cv::Point pt2, cv::Point pt0) { double dx1 = pt1.x - pt0.x; double dy1 = pt1.y - pt0.y; double dx2 = pt2.x - pt0.x; double dy2 = pt2.y - pt0.y; return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10); } /** * Helper function to display text in the center of a contour */ void setLabel(cv::Mat& im, const std::string label, std::vector& contour) { int fontface = cv::FONT_HERSHEY_SIMPLEX; double scale = 0.4; int thickness = 1; int baseline = 0; cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline); cv::Rect r = cv::boundingRect(contour); cv::Point pt(r.x + ((r.width - text.width) / 2), r.y + ((r.height + text.height) / 2)); cv::rectangle(im, pt + cv::Point(0, baseline), pt + cv::Point(text.width, -text.height), CV_RGB(255,255,255), CV_FILLED); cv::putText(im, label, pt, fontface, scale, CV_RGB(0,0,0), thickness, 8); } int main(int argc, char** argv) { //cv::Mat src = cv::imread("polygon.png"); cv::Mat src = cv::imread(argv[1]); if (src.empty()) return -1; // Converti in scala di grigi cv::Mat gray; cv::cvtColor(src, gray, CV_BGR2GRAY); // Utilizzare Canny invece di soglia per la cattura di piazze con ombreggiatura gradiente cv::Mat bw; cv::Canny(gray, bw, 0, 50, 5); // Trova contorni std::vector> contours; cv::findContours(bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); std::vector approx; cv::Mat dst = src.clone(); for(unsigned int l=0;l

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>