4

What's wrong with this - why won't it draw the circle in the window I create?

    threeDWinName = "3D View"
    cv2.namedWindow(threeDWinName, cv2.CV_WINDOW_AUTOSIZE)
    img2 = cv2.imread('white.png', 0)
    cv2.imshow(threeDWinName,img2)
    cv2.circle(img2, (100,100),100,255,-1)
    cv2.imshow(threeDWinName,img2)

1 Answer 1

7

Your code works for me. I see the file you are reading is called white.png, and by loading it with the 0 you are loading it in grayscale, so the circle you are drawing is also white. That could be the problem ;)

img2 = cv2.imread('black.png', 0)
cv2.circle(img2, (100,100),100,255,-1)
cv2.imwrite('circle.png', img2)

enter image description here

or if you use img2 = cv2.imread('black.png'), then you get this:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your help again. Why does the grayscale representation of a blue circle go white? I gave up on trying to make a background because I couldn't get the circle draw function work, so figured I'd use my own background image. Not efficient I know,...
@Sam Heather - Hey, happy to help. For grayscale images the value between 0 and 255 is a shade of grey, from black to white. For colour images, usually you would pass a tuple of three values, like this (255,0,0) This represents the luminousity of each of the channels Blue, Green, and Red (or BGR). But in your case you've only passed a single value, and the function has interpreted it as the value for the first (Blue) channel. If you pass (0,0,255), you'll get a red circle. Try changing the values to generate different colours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.