From 842e8303a35db1d48c6037ec28c4f7ca16a74744 Mon Sep 17 00:00:00 2001 From: LeoDJ Date: Fri, 21 Jul 2023 19:22:36 +0200 Subject: [PATCH 1/2] add Windows compatibility hopefully without breaking Linux support --- src/tc001v4.2.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tc001v4.2.py b/src/tc001v4.2.py index 8346f7d..b1568ba 100644 --- a/src/tc001v4.2.py +++ b/src/tc001v4.2.py @@ -29,6 +29,7 @@ import argparse import time import io +import platform #We need to know if we are running on the Pi, because openCV behaves a little oddly on all the builds! #https://raspberrypi.stackexchange.com/questions/5100/detect-that-a-python-program-is-running-on-the-pi @@ -51,14 +52,20 @@ def is_raspberrypi(): dev = 0 #init video -cap = cv2.VideoCapture('/dev/video'+str(dev), cv2.CAP_V4L) +if platform.system() == 'Windows': + cap = cv2.VideoCapture(int(dev)) +else: + cap = cv2.VideoCapture('/dev/video'+str(dev), cv2.CAP_V4L) #cap = cv2.VideoCapture(0) #pull in the video but do NOT automatically convert to RGB, else it breaks the temperature data! #https://stackoverflow.com/questions/63108721/opencv-setting-videocap-property-to-cap-prop-convert-rgb-generates-weird-boolean if isPi == True: cap.set(cv2.CAP_PROP_CONVERT_RGB, 0.0) else: - cap.set(cv2.CAP_PROP_CONVERT_RGB, False) + try: + cap.set(cv2.CAP_PROP_CONVERT_RGB, False) + except TypeError: + cap.set(cv2.CAP_PROP_CONVERT_RGB, 0) # on Windows (and maybe other platforms) OpenCV expects 0 instead of False #256x192 General settings width = 256 #Sensor width @@ -97,6 +104,9 @@ def snapshot(heatmap): # Capture frame-by-frame ret, frame = cap.read() if ret == True: + if platform.system() == 'Windows': # on Windows, OpenCV outputs the frame in a different format + frame = np.reshape(frame[0], (192*2, 256, 2)) # if there's a "can't reshape size xxxx into shape ..." error here, you most likely used the wrong --device ID + imdata,thdata = np.array_split(frame, 2) #now parse the data from the bottom frame and convert to temp! #https://www.eevblog.com/forum/thermal-imaging/infiray-and-their-p2-pro-discussion/200/ From 7de78d8b70ea6ef90675e2ee922950490640f4f5 Mon Sep 17 00:00:00 2001 From: LeoDJ Date: Fri, 21 Jul 2023 19:24:32 +0200 Subject: [PATCH 2/2] fix indentation error? --- src/tc001v4.2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tc001v4.2.py b/src/tc001v4.2.py index b1568ba..7e8fc14 100644 --- a/src/tc001v4.2.py +++ b/src/tc001v4.2.py @@ -358,6 +358,6 @@ def snapshot(heatmap): if keyPress == ord('q'): break - capture.release() - cv2.destroyAllWindows() +cap.release() +cv2.destroyAllWindows()