Python Software

The Windows software is distributed as an exe, and is not available for Mac or Linux. In order to use with other platforms, you can use Python and opencv, which has interface hooks to read video camera frames.

Mac OS X Only!

Right now the Python code is only tested on Mac. When we tried running the working opencv code in Windows (opencv-python 4.2.0.34) and got these errors:
Download: file
> python cam2.py
Camera 0 open at size: (240 x 321)
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1113) SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -2147023727
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1125) SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -2147023727
[ WARN:1] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1159) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147023727
Failed to fetch frame
[ WARN:1] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (1159) CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638

If you know what this could be due to, please open an issue at https://github.com/adafruit/Adafruit_UTI165_Camera

For Mac users:

Try out this example code, which will fetch frames and display them in opencv. Nothing else fancy is done, but you can build on this example!

import numpy as np
import time
import cv2
import struct

camera_num = 0

for camera_num in range(6):
    cam = cv2.VideoCapture(camera_num)
    if not cam.isOpened():
        print("Was not able to open camera", camera_num)
        cam.release()
        continue
    if not cam.set(3, 240):
        print("Was not able to set camera", camera_num, "width to 240 pixels")
        cam.release()
        continue
    if not cam.set(4, 321):
        print("Was not able to set camera", camera_num, "height to 321 pixels")
        cam.release()
        continue
    if cam.get(3) != 240:
        print("Was not able to set camera", camera_num, "width to 240 pixels")
        cam.release()
        continue
    break

print("Camera %d open at size: (%d x %d) %d FPS" % (camera_num, cam.get(3), cam.get(4), cam.get(5)))

cv2.namedWindow('Thermal Camera - Press Q to quit', cv2.WINDOW_NORMAL)
cv2.resizeWindow('Thermal Camera - Press Q to quit', 480, 642)

while(True):
    # Capture frame-by-frame
    ret, frame = cam.read()

    if not ret:
        print("Failed to fetch frame")
        time.sleep(0.1)
        continue
    #print("Frame OK!")
    colorframe = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
    # Display the resulting frame
    cv2.imshow('Thermal Camera - Press Q to quit', colorframe)
    
    cam.set(cv2.CAP_PROP_CONVERT_RGB, 0)
    ret, frame = cam.read()
    if not ret:
        print("Failed to fetch frame")
        time.sleep(0.1)
        continue
    print("Frame OK! for temp calculation")
    print(struct.unpack("h", frame[320][0])[0]/10)
    cam.set(cv2.CAP_PROP_CONVERT_RGB, 1)

    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    #yuvframe = cv2.cvtColor(frame, cv2.COLOR_RGB2YUV)
    #print(yuvframe[-1][0:3])
cam.release()
cv2.destroyAllWindows()

Run it at the command line with the camera plugged in!

% python opencv_uti165k.py

You may need to install opencv python package first with pip install opencv-python

The output will be exactly what is on the scanner's TFT display.

This guide was first published on Apr 29, 2020. It was last updated on Apr 29, 2020.
This page (Python Software) was last updated on Jul 14, 2020.