leswright1977 / PyThermalCamera

Python Software to use the Topdon TC001 Thermal Camera on Linux and the Raspberry Pi
Apache License 2.0
195 stars 41 forks source link

Pressing q for fullscreen crashes the program #9

Open fuzzy7k opened 9 months ago

fuzzy7k commented 9 months ago

While running on PurseOS 10 with Phosh, attempting to run fullscreen causes the window to crash. There are no messages on the console or in the journal. It just closes and I am not sure how to debug further.

fuzzy7k commented 9 months ago

Initializing the window fullscreen works good.

tew2012 commented 9 months ago

got the same problem on a Raspberry Pi, no error message. What did you do to get it work? I don't need to switch it. It could always run in fullscreen mode.

fuzzy7k commented 9 months ago
-dispFullscreen = False
-cv2.namedWindow('Thermal',cv2.WINDOW_GUI_NORMAL)
+dispFullscreen = True
+cv2.namedWindow('Thermal',cv2.WND_PROP_FULLSCREEN)
+cv2.setWindowProperty('Thermal',cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
tew2012 commented 9 months ago

Thanks for the fast reply!

I tried it, but it still doesn't start in fullscreen on a Pi (4). And when I press q (for fullscreen) there is a frameless picture of the output on the left top side for a few milli seconds on the desktop. Then the script stopped working, no error message (even with -v).

the scale option (keys d and c) doesn't change the window size. It changes the font and crosshair size. (maybe that explains why fullscreen doesn't work?)

When I change lines 294 and 302 from

if dispFullscreen == False and isPi == False:

to if dispFullscreen == False and isPi == True:

then the script executes cv2.resizeWindow('Thermal', newWidth,newHeight) after rescaling and that works on a Pi as expected.

below is a link to an example of a py (MLX) thermal script from another project which uses the same commands to go into fullscreen and this script actually works (with an MLX chip). Any ideas to make the PyThermalCamera script go into fullscreen on a Pi (4).

https://myshare.leuphana.de/?t=8096f1b371e565d325914e8ff45cd9a9

    cv2.namedWindow('Thermal Image', cv2.WND_PROP_FULLSCREEN)
    cv2.setWindowProperty('Thermal Image',cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
tew2012 commented 9 months ago

I found the problem. q starts fullscreen mode and at the same time quits the application. It works after changing the quit key (second block).

    if keyPress == ord('q'): #enable fullscreen
        dispFullscreen = True

.... if keyPress == ord('q'): break capture.release() cv2.destroyAllWindows()

fuzzy7k commented 9 months ago

I found the problem. q starts fullscreen mode and at the same time quits the application. It works after changing the quit key (second block).

Hah! good catch.

I suppose I should have included line numbers with those modifications. I changed the init code toward the top.

diff --git a/src/tc001v4.2.py b/src/tc001v4.2.py
index a537d36..625bed7 100644
--- a/src/tc001v4.2.py
+++ b/src/tc001v4.2.py
@@ -69,8 +69,9 @@ newHeight = height*scale
 alpha = 1.0 # Contrast control (1.0-3.0)
 colormap = 0
 font=cv2.FONT_HERSHEY_SIMPLEX
-dispFullscreen = False
-cv2.namedWindow('Thermal',cv2.WINDOW_GUI_NORMAL)
+dispFullscreen = True
+cv2.namedWindow('Thermal',cv2.WND_PROP_FULLSCREEN)
+cv2.setWindowProperty('Thermal',cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
 cv2.resizeWindow('Thermal', newWidth,newHeight)
 rad = 0 #blur radius
 threshold = 2
fuzzy7k commented 9 months ago

Instead of changing the quit key, I changed the Fullscreen key to 'e'.

tew2012 commented 9 months ago

Thank you!!

fuzzy7k commented 9 months ago

Not sure where to drop this, so I'll do it here. I started a branch to make this more user friendly on the Librem5. It works on the Pinephone too. It includes a patch that triggers fullscreen on phosh devices. q remains Quit. https://github.com/fuzzy7k/PyThermalCamera/

It still needs some work to restore rotation settings after closing. I might create some pull requests, but the author does not seem entirely active.

There is a helper/install script to install udev and systemd files on linux that will automatically launch the program on plugin. The automatic launch on plugin only works on the p2pro, as that is what I have, Adding tc001 vid,pid to the udev file should make it work.