92es / Thermal-Camera-Redux

Topdon TC001 (and clone) thermal camera app to read and display live and offline thermal data
38 stars 9 forks source link

Frozen image on WSL2/Ubuntu 22.04 #5

Closed JimKnopfIoT closed 1 month ago

JimKnopfIoT commented 2 months ago

I tried to run the Infiray P2 Pro on Windows WSL2 using Ubuntu 22.04. Installation was easy, getting it the USB Camera to work as /dev/video0 was tricky. I had to compile my own kernel and use a .wslconfig file in my Windows home dir to point to that kernel. I attached the Camera in Powershell using usbipd list usbipd bind -b 2-6 usbipd attach --wsl --busid 2-6

Now in WSL2, v4l2-ctl --list-devices --all show me this:

USB Camera: USB Camera (usb-vhci_hcd.0-1):
        /dev/video0
        /dev/video1
        /dev/media0

Driver Info:
        Driver name      : uvcvideo
        Card type        : USB Camera: USB Camera
        Bus info         : usb-vhci_hcd.0-1
        Driver version   : 5.15.150
        Capabilities     : 0x84a00001
                Video Capture
                Metadata Capture
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps      : 0x04200001
                Video Capture
                Streaming
                Extended Pix Format
Media Driver Info:
        Driver name      : uvcvideo
        Model            : USB Camera: USB Camera
        Serial           : 200901010001
        Bus info         : usb-vhci_hcd.0-1
        Media version    : 5.15.150
        Hardware revision: 0x00001101 (4353)
        Driver version   : 5.15.150
Interface Info:
        ID               : 0x03000002
        Type             : V4L Video
Entity Info:
        ID               : 0x00000001 (1)
        Name             : USB Camera: USB Camera
        Function         : V4L2 I/O
        Flags            : default
        Pad 0x01000007   : 0: Sink
          Link 0x02000010: from remote pad 0x100000a of entity 'Extension 4' (Video Pixel Formatter): Data, Enabled, Immutable
Priority: 2
Video input : 0 (Input 1: ok)
Format Video Capture:
        Width/Height      : 256/384
        Pixel Format      : 'YUYV' (YUYV 4:2:2)
        Field             : None
        Bytes per Line    : 512
        Size Image        : 196608
        Colorspace        : sRGB
        Transfer Function : Rec. 709
        YCbCr/HSV Encoding: ITU-R 601
        Quantization      : Default (maps to Limited Range)
        Flags             :
Crop Capability Video Capture:
        Bounds      : Left 0, Top 0, Width 256, Height 384
        Default     : Left 0, Top 0, Width 256, Height 384
        Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 256, Height 384, Flags:
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 256, Height 384, Flags:
Streaming Parameters Video Capture:
        Capabilities     : timeperframe
        Frames per second: 25.000 (25/1)
        Read buffers     : 0

User Controls

                     brightness 0x00980900 (int)    : min=-64 max=64 step=1 default=0 value=0
                       contrast 0x00980901 (int)    : min=0 max=100 step=1 default=50 value=50
                     saturation 0x00980902 (int)    : min=0 max=100 step=1 default=64 value=64
                            hue 0x00980903 (int)    : min=-180 max=180 step=1 default=0 value=0
        white_balance_automatic 0x0098090c (bool)   : default=1 value=1
                          gamma 0x00980910 (int)    : min=100 max=500 step=1 default=300 value=300
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1 (50 Hz)
                                0: Disabled
                                1: 50 Hz
                                2: 60 Hz
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=10 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=100 step=1 default=50 value=50
         backlight_compensation 0x0098091c (int)    : min=0 max=1 step=1 default=0 value=0

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=3 default=3 value=3 (Aperture Priority Mode)
                                1: Manual Mode
                                3: Aperture Priority Mode
         exposure_time_absolute 0x009a0902 (int)    : min=50 max=10000 step=1 default=166 value=166 flags=inactive
     exposure_dynamic_framerate 0x009a0903 (bool)   : default=0 value=1

I can start using sudo ./redux -d 0. The screen is blue and show -273°C, a bit too cold. geany_T2W4j8c6gz

92es commented 2 months ago
"I tried to run the Infiray P2 Pro on Windows WSL2 using Ubuntu 22.04."

Another configuration never tried before.

The info menu is showing [SRC: ERROR] indicating it can't read from the camera.

The info menu is also showing "Freeze" which is short for "Freeze Frame" indicating the USB connection was lost.

The -273.1 C temps are Zero Kelvin meaning empty thermal frame data.

The blue background is the 1st entry ( coldest color ) in the colormap.

float kelvin2Celsius(unsigned short kelvin) { // # LeoDJ's Kelvin conversion algorithm, post #216
        return ( ((float)kelvin / 64.0) - 273.15 );
}

Did you get this error message on stdout / stderr ?

ERROR: Frame is empty, switching to freeze frame.
Fix camera connection and then press 'e' to exit freeze frame.

This can happen if there are loose USB cable connections (usually at the camera side).

If so, try disconnecting and reconnecting your USB cable (at both ends) and then press 'e' in the window to tell the app to try and re-establish USB connections.

If connections are re-established, "Freeze Frame" will switch back to "Live Video" mode (after pressing the 'e' key).

92es commented 2 months ago

Just looked up what WLS2 is.

WARNING: Running Linux as a guest OS in a VM may not work because of the way the host presents the USB device data to the guest OS.

I tried this using a Linux VirtualBox Host and a RPi Desktop guest OS.

The app complied and ran, but there was no valid thermal data. The VM changed the video data being presented to the guest app. In my case, VirtualBox passed lossy compressed video data (vs raw lossless video data) to the thermal camera app so the thermal data was forever scathed and unusable.

92es commented 1 month ago

Closing issue because app is running as a client of a guest OS in a virtual machine. Virtual machines can and will alter the USB video feed being passed to the guest OS, thus destroying the thermal data.

Verified working natively on Ubuntu 24.04.