1

I try again to do better my question (http://stackoverflow.com/questions/14349550/convert-image-in-a-binary-image-with-cv2-module-in-python)

In this code (it's a little bit changed from the first ) I can easily work with my converted binary image , extracting contours, calculating areas.. but it's not again possible to execute this code line: cv2.imshow('gray_image',imgray).

it show me a total grey window and that's all. I have to quit python because goes in loop.

imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0) 
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
print('oggetti trovati')
print(len(contours))
cnt = contours[0]
print(len(cnt))
cv2.imshow('gray_image',imgray)

What can I do?

2
  • 1
    Just wonder if you have cv2.waitKey() after cv2.imshow(..)? Commented Jan 17, 2013 at 1:18
  • Why now it's work? I try similar work with scikit-image and matplotlib.pyplot and is not necessary! It cannot execute code showing image and execute other code? Commented Jan 17, 2013 at 1:24

1 Answer 1

4

Here you need to add cv2.waitKey() after cv2.imshow('gray_image',imgray). This function is for handling any window event like creating or showing an image in OpenCV.

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

Comments

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.