2

I am trying to apply threshold to an image, but I get the following error :

TypeError: 'unknown' is not a numpy array

I get this error on the cv2.imshow() line.

Here is my code :

import cv2
import numpy as np
img = cv2.imread('...',0)
img2 = cv2.imread('...',0)
fImg = cv2.addWeighted(img.astype(np.float32), 0.9, img2.astype(np.float32), 0.1, -20.0)
th = cv2.threshold(fImg, 127, 255, cv2.TRESH_BINARY)
cv2.imshow('th', th)
cv2.waitKey(0)
cv2.destroyAllWindows

Thanks in advance for your help !

1 Answer 1

4

cv2.threshold returns a tuple (retval, dst), where dst is the transformed matrix. You need to pass dst to cv2.imshow instead of the returned tupled, after checking if retval is valid

retval, th = cv2.threshold(fImg, 127, 255, cv2.TRESH_BINARY)
if retval:
    cv2.imshow('th', th)
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.