Home > Back-end >  Regarding opencv hoff circle detection, bosses, look at the reasons I got more than six hours not ye
Regarding opencv hoff circle detection, bosses, look at the reasons I got more than six hours not ye

Time:01-02

This two days in learning opencv, but it is pit TMD,
But about some opencv + vs2019 configuration of the hole I have in the past and now lay down on the hoff round testing here,
Opencv I use version is 4.3.0 version, had always thought that is where to set out, then I will perform the same operation in python, even hoff function parameters are the same, as a result, the detected the python, c + + code anyway detection not to come out, I also find on the Internet a lot of c + + code, no one can be detected, so I want to ask bosses is my version of the opencv wrong or what the reason,
Below is my python code and c + + code comparison:
First on one piece of artwork:

 
The import cv2 as CV
The import numpy as np

Planets=CV. Imread (" 22. JPG ")
Gay_img=CV. CvtColor (planets, CV. COLOR_BGRA2GRAY)
Img=CV. MedianBlur (gay_img, 7) #, with median fuzzy denoising point
Cimg=CV. CvtColor (img, CV. COLOR_GRAY2BGR)

Circles=CV. HoughCircles (img, CV. HOUGH_GRADIENT, 1, 50, param1=200, param2=40, minRadius=4, maxRadius=500)

Circles=np. Uint16 (np) around (circles))
Print (circles)


For I circles in [0, :] : # ergodic matrix each line of data
CV. Circle (planets, (I [0], I [1]), I [2], (0255, 0), (2)
CV. Circle (planets, (I [0], I [1]), 2, (0,0,255), 3)


CV. Imshow (" gay_img planets)
CV. WaitKey (0)
CV. DestroyAllWindows ()

Then after the python implementation results:


Below is a c + + :
 
# include
# include & lt; Opencv2 highgui/highgui_c. H>
# include & lt; Iostream>
# include & lt; Stdio. H>
# include

using namespace std;
Using the namespace CV;

Int main ()
{
Mat SRC=https://bbs.csdn.net/topics/imread (" 22. JPG ");
NamedWindow (" 1 ");
Imshow (" input ", SRC);
Mat gray;
MedianBlur (SRC, SRC, 7);
CvtColor (SRC, gray, COLOR_RGB2GRAY);
Vector//(the original gray image, the center of a circle with radius (x, y, r), the method of resolution, the center point of minimum distance, canny high threshold, accumulator threshold, the minimum radius of the circle, maximum radius of the circle)
HoughCircles (gray, circles, HOUGH_GRADIENT, 1, 100, 200, 40, 4, 500);
Cout & lt; For (size_t t=0; T & lt; Circles. The size (); T++) {
Point center (circles [t] [0], circles [t] [1]).
Float the radius=round (circles [t] [2]).

Circle (SRC, center, and 3, Scalar (255, 0, 0), 2, 8, 0).
Circle (SRC, center, the radius, Scalar (0, 0, 255), 3, 8, 0).
}
NamedWindow (" out ");
Imshow (" hough circle demo, "SRC);
WaitKey (0);
return 0;
}


This is a c + + run results:

Here I have a print circals under the size in the code, but by adjusting the parameters of hoff function, the size is not zero, is a huge number, and there will be an error in a painting circle: (by the way here imshow () function of the code how to solve ah, I tried GB2312, GB2312-80, such as utf8 encoding are no,)
The
reference

Ah, Python is really yyds, because I was looking for online several bloggers c + + code, they can run out of the results I still won't do, vs2019 free community edition does not know what is going on, the debug when a breakpoint is not to stop, just passed, I found several methods on the net, or breakpoint don't stop, don't give me the opportunity of entering function directly is an error, so please only the bosses, I this is wrong, is wrong with opencv version,