Reputation: 117
I have made a dictionary,done some calculations and returned some values. Now i'm trying to print those returned values on an image, but I get this error:
expected string or Unicode object, int found
let's say my returned value is:
(58, 47, 88.0)
and I'm using the following to display it on a screen:
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, T ,(619,351), font, 1,(0,0,255),2,cv2.LINE_AA)
Also, I want to be able to display on the image: T = (58, 47, 88.0)
Upvotes: 1
Views: 10407
Reputation: 260
putting str() around the text to be printed really works for me here. I m surprised the error was showing for a different argument even though a previous argument had the actual error
Upvotes: 1
Reputation: 22954
You seem to be going in right direction I guess, The code looks good enough, But there is a TypeError
which indicates that you have passed an Integer in place of a string and most probably, that mistake must be somewhere in the value of T
, Check if it's of type int
, you can always check the type of any variable using type(T)
, If it returns int
then you probably need to typecast the variable as str(T)
so the final code may look like:
if not type(T) is str:
try:
cv2.putText(img, str(T) ,(619,351), font, 1,(0,0,255),2,cv2.LINE_AA)
except Exception,e:
print e
Upvotes: 5