Python Script For PI - Page 1
Forum section: electronics / general

author: OutoftheBox
author_rank: Newbie
timestamp: December 14, 2023, 05:31:43 pm
content: Looking to use a thermal camera and raspberry pi zero 2w for a project. I have it working, with Les Wright's PyThermalCamera python script. The raw.py script is close to what i want as it appears to have less lag, doesn't have thermal data overlay, and appears to have a sharper image then the tc001v4.2.py version. However, the raw isn't scalable or capable of full screen and has the duplicate green data below. Is there an easy script to create this... im a noob in python? Thanks for any help!

author: Amish Technician
author_rank: Contributor
timestamp: December 15, 2023, 04:46:43 pm
content: Have you seen this project? The overlays can be turned off, and it can go full screen.https://www.eevblog.com/forum/thermal-imaging/rasbpi-and-topdon-tc001-(guinea-pig)-tester-requested/

author: G28
author_rank: Regular Contributor
timestamp: December 18, 2023, 08:05:13 am
content: Quote from: OutoftheBox on December 14, 2023, 05:31:43 pmWhat exactly are you looking for the Python script to do ?The 2nd Python script has integer scaling and if you want that added to the 1st script, that is fairly easy.You can also eliminate the 2nd-subframe fairly easily.Python is slow and single threaded so you won't get it to go faster than the raw.py script which doesn't mine any of the thermal data.If those are the only 2 functions you want, that is easy, especially if you don't want to change scale while in use, just static sized video playback.

author: G28
author_rank: Regular Contributor
timestamp: December 20, 2023, 11:28:58 pm
content: Quote from: OutoftheBox on December 14, 2023, 05:31:43 pmOutOfTheBox and those that are interested.Here is the raw script modified to:- split the frame into the separate image and thermal sub frames- only display the image frame- scale the window and image sub-frame to 3X native resolution- apply the JET colormap so image sub-frame is no longer monochromeHope this helps.Code:#!/usr/bin/env python3import cv2import numpy as npimport argparseparser = argparse.ArgumentParser()parser.add_argument("--device", type=int, default=0, help="Video Device number e.g. 0, use v4l2-ctl --list-devices")args = parser.parse_args()if args.device:dev = args.deviceelse:dev = 0#init videocap = cv2.VideoCapture('/dev/video'+str(dev), cv2.CAP_V4L)#cap.set(cv2.CAP_PROP_CONVERT_RGB,False)cap.set(cv2.CAP_PROP_CONVERT_RGB,0.0)#we need to set the resolution here why?'''wright@CF-31:~/Desktop$ v4l2-ctl --list-formats-extioctl: VIDIOC_ENUM_FMTIndex : 0Type : Video CapturePixel Format: 'YUYV'Name : YUYV 4:2:2Size: Discrete 256x192Interval: Discrete 0.040s (25.000 fps)Size: Discrete 256x384Interval: Discrete 0.040s (25.000 fps)'''scale = 3width = (256 * scale)height = (192 * scale)name = 'Thermal'cv2.namedWindow(name,cv2.WINDOW_GUI_NORMAL)cv2.resizeWindow(name, width, height) # Scale window once to desired scalewhile(cap.isOpened()):# Capture frame-by-frameret, frame = cap.read()if ret == True:cv2.namedWindow(name,cv2.WINDOW_NORMAL)imdata,thdata = np.array_split(frame, 2) # Split into individual sub-framesimdata = cv2.cvtColor(imdata, cv2.COLOR_YUV2BGR_YUYV)imdata = cv2.resize(imdata, (width, height), cv2.INTER_CUBIC)imdata = cv2.applyColorMap(imdata, cv2.COLORMAP_JET)cv2.imshow(name,imdata)keyPress = cv2.waitKey(3)if keyPress == ord('q'):breakcapture.release()cv2.destroyAllWindows()

author: OutoftheBox
author_rank: Newbie
timestamp: March 27, 2024, 07:41:49 pm
content: Thank you all for the replies! You guys are amazing. I was able to get it working. This is a really cool community

author: OutoftheBox
author_rank: Newbie
timestamp: April 30, 2024, 07:12:42 pm
content: Thanks so much for your previous help... Recently, I have tried to upgrade my project with a Infiray XH09 X2 as it has a better lens for distant observations and higher frame rate. The code does not work for this usb device. It will start for a second like my previous camera and then bluescreen. I have tried modifying the code, but am lost... Any ideas?