index

Using WaveShare LWIR Thermal Camera with Python

Hardware

Software

  • Python (tested on Python 3.11)

Create Virtual Environment

Using venv

python3 -m venv lwir-env
source lwir-env/bin/activate

Using conda

conda create -n lwir-env python=3.11 -y
conda activate lwir-env

Clone SenXor Lite Library

git clone https://github.com/MeridianInnovation/pysenxor-lite.git
cd pysenxor-lite

Checkout Specific Commit

At the time of writing the latest commit 37d222f doesn’t work, therefore we are checking out an earlier commit.

git checkout b2568478985f5b0f487013a1db340e8bc81e9c1f

Install SenXor Lite

python -m pip install .

Create Test Script

nano thermal_camera_test.py

Add the following code:

import senxor
import numpy as np
import matplotlib.pyplot as plt
import sys
import time

OUTPUT_FILE = "frame.png"

def main():
    # List devices
    addrs = senxor.list_senxor()
    print(f"Found {len(addrs)} device(s)")

    if len(addrs) == 0:
        print("❌ No SenXor devices found")
        sys.exit(1)

    # Connect to first device
    print(f"🔌 Connecting to {addrs[0]}")
    dev = senxor.connect(addrs[0])

    try:
        # Start stream
        dev.start_stream()
        print("▶️ Stream started")

        # Give sensor a moment to stabilize
        time.sleep(0.2)

        # Read one frame
        header, frame = dev.read()

        if frame is None:
            print("❌ Failed to read frame")
            sys.exit(1)

        print(f"📸 Frame captured: shape={frame.shape}, dtype={frame.dtype}")

        # Normalize temperature data to 0–255 for visualization
        vis = senxor.proc.normalize(frame, dtype=np.float32)

        # Save as PNG
        plt.figure(figsize=(6, 5))
        plt.imshow(vis, cmap="inferno")
        plt.colorbar(label="Normalized intensity")
        plt.axis("off")
        plt.tight_layout()
        plt.savefig(OUTPUT_FILE, dpi=150)
        plt.close()

        print(f"✅ Snapshot saved to {OUTPUT_FILE}")

    finally:
        dev.close()
        print("🔒 Device closed")

if __name__ == "__main__":
    main()

Install Test Script Dependencies

pip install numpy matplotlib 

Run Test Script

python thermal_camera_test.py

You should see output indicating the device was found, a frame was captured, and a PNG file was saved. Open frame.png to view the thermal image!