Skip to content
Advertisement

Can’t convert object of type ‘function’ to ‘str’ for ‘text

Good day everyone I’m sorry I’m new to python programming sorry if I’m asking this even this is basic or not. Someone can help me with this? The problem is I want to put the data that has been read by my Pyserial from my Arduino temperature sensor but I don’t know how.

Here code for the Temperature to pyserial:

JavaScript

And here’s the whole code that I want to show in my PutText on opencv:

JavaScript

and I got this error when I run it:

JavaScript

Even If I don’t put the temperature code into function It run the pyserial 1st before the opencv. Please Help I don’t know what to do. Please

Advertisement

Answer

presumably you want to sample your temperature 50 times and then return a single value?

JavaScript

then in your opencv call use get_temp(ser) instead of tempe

where ser is a serial instance thats already open

if taking 50 samples is too slow then you can always take less samples with get_temp(ser,5) to only take 5 samples for example … if you want the mode or median instead of the mean then i would recommend just using numpy.mode or numpy.median instead of calculating it (its probably faster to use numpy.mean than calculating the average manually)

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement