Currently, Hough transform detects circles
Examine all pixels inside the detected circle
hsv = cv2.cvtColor (img, cv2.COLOR_BGR2HSV) bin_img = cv2.inRange (hsv, (30, 40, 0), (90, 255, 255))
If 70% or more of one circle meets the conditions, draw a circle.
I created a program that does not draw if it is less than.
Corresponding source code
Traceback (most recent call last): File "E: \ K \ pg \ test.py", line 58, in<module> if bin_img [j, i] == 0: IndexError: index 594 is out of bounds for axis 0 with size 594
What i don't understand
hsv = cv2.cvtColor (img, cv2.COLOR_BGR2HSV) bin_img = cv2.inRange (hsv, (30, 40, 0), (90, 255, 255)) count1 = 0 count2 = 0 # Draw the detection result. if circles is not None: circles = circles.squeeze (axis = 0) # (1, NumCircles, 3)->(NumCircles, 3) for cx, cy, r in circles.astype (int): Set #i and j to the range of the rectangle from end to end of the circle for i, j in zip (range (cx-r, cx + r), range (cy-r, cy + r)): a = (cx, cy) b = (i, j) Calculate the distance between # (i, j) and the center of the circle (cx, cy) answer = distance.euclidean (a, b) # When the distance answer is within r, count. if answer<= r: count1 + = 1 # Count when the color inside the circle meets the conditions. if bin_img [j, i] == 0: count2 + = 1 continue #Draw a circle if 30% of the inside of the circle does not meet the conditions (70% of the inside of the circle meets the color conditions) if (count2/count1) * 100<= 30: # Draw a circle # Draw the circumference of the circle. cv2.circle (img, (cx, cy), r, (0, 255, 0), 2)
Before tampering with the relevant source code (at the time of the previous question)
if bin_img [j, i] == 0:
I didn't get an error due to this, so I don't know why it happened.
Is there something wrong with the code in another part?
Answer # 1
It was an error that occurred because I was looking at the pixels, exceeding the image size 1056x594!
- python - opencv color range
- python - opencv circle center color
- python opencv face recognition multiple person image
- python - color discrimination and color replacement for each pixel by machine learning
- python - [opencv] i want to display the area of each object at the position adjacent to the object
- python - [opencv] i can't get the frame of the video with read (), and the playback of the video stops halfway
- python - pyrhon save colored dataframe color turns black
- how to change index settings in python
- python - i got an error in opencv
- python style i want to know the background color + maximum value
- image composition using python opencv
- python - i want to extract only the dataframe index of 500ms
- python - conditional branching by color inside the circle detected by hough transform
- python - opencv videocapture cannot be used
- python opencv
- python - detect whole body and upper body with opencv
- python - i don't see the error in the face cropping program with opencv
- python - display of atomic index in rdkit
- python opencv recording time