0

I have the following simple script to capture and show stream from a thermal camera:

import cv2


camera_index = 0
cap = cv2.VideoCapture(camera_index)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
cap.set(cv2.CAP_PROP_BRIGHTNESS, 0.5)
cap.set(cv2.CAP_PROP_WB_TEMPERATURE, 3500)

while True:
    ret, frame = cap.read()
    cv2.imshow('Thermal camera', frame)
    key = cv2.waitKey(1)
    if key == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

I am not able to get correct images using this script, the image I am getting in return looks like this:

enter image description here

I believe I am doing something wrong here with colors and formats as I expect a black-and-white thermal image from this.

Edit:

Camera: Optis Xi 400 Frame shape: (290, 382, 3) Frame type: uint8

vwertuzy
  • 171
  • 1
  • 2
  • 12
  • that looks like a pixel contains four bytes. – Christoph Rackwitz Mar 28 '23 at 12:19
  • You could mention your camera make/model and operating system. You could print `frame.shape` and `frame.dtype` immediately after `cap.read()`. – Mark Setchell Mar 28 '23 at 13:15
  • Are you using a process interface? Are you configuring the camera's setting or are they preset? – Ori Yarden PhD Mar 28 '23 at 16:24
  • @OriYarden the camera is just plugged in through USB, no other settings are interfaced. – vwertuzy Mar 28 '23 at 16:31
  • Are you sure this camera is supported? It seems to be ignoring your 640x480 size setting and giving you 290x382 in colour. Have you tried inspecting the first few bytes with `print(frame.ravel()[:20])` – Mark Setchell Mar 28 '23 at 16:39
  • Do some trial-and-error with the `cv2.CAP_PROP_BRIGHTNESS` and `cv2.CAP_PROP_WB_TEMPERATUR` parameters (if they're even actually setting anything) and input a range of values. You can also try Bonsai's (animal tracking software) camera capture to see if it get any sort of image. Otherwise, try using the software packages recommended on the website. It doesn't look like no image, but it's not really showing anything in the image you provided. – Ori Yarden PhD Mar 28 '23 at 16:48
  • @MarkSetchell I think it is just the size of the image, so it is not able to go up to 640x480. frame.ravel()[:20] returns `[ 0 255 26 0 255 35 0 255 27 0 255 4 0 232 0 26 255 75 0 255]` – vwertuzy Mar 28 '23 at 16:48
  • In [other questions](https://stackoverflow.com/questions/66909370/thermal-image-processing) I encountered about thermal cameras, the camera output was 16 bits per pixel. The camera output is never colored, and the automatic conversion to BGR applied by OpenCV messes with the video. Try adding `video.set(cv2.CAP_PROP_CONVERT_RGB, 0)`, and also try `cap.set(cv2.CAP_PROP_FORMAT, -1)`. Read the frame as `764x290` and then use `frame.view(np.uint16)`. There are cases when data is signed `frame.view(np.int16)`. There are cases when data is big endian, and bytes should be swapped. – Rotem Mar 29 '23 at 20:56

0 Answers0