User avatar
HermannSW
Posts: 4519
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Crosshair and grid lines

Sun Aug 01, 2021 7:24 pm

Nice, picamera overlays (there can be many) do not need camera preview window (it is an overlay as well).
Unfortunately raspistill cannot run while picamera camera object is active, and without the overlay disappears:
snapshot.png
snapshot.png
snapshot.png (65.29 KiB) Viewed 1113 times

But picamera is open source -- if I can strip it down that just an overlay can be placed without blocking the camera, then we have arbitrary overlays that will work above raspistill/raspivid preview window!
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4519
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Crosshair and grid lines

Sun Aug 01, 2021 7:53 pm

Nice -- that was easy!
I had to call camera.close() to free camera for raspistill/raspivid use.
But that closes all overlays as well.
This simple diff in picamera/camera.py does what I want:

Code: Select all

         assert not self.recording
-        for overlay in list(self._overlays):
-            self.remove_overlay(overlay)
+#        for overlay in list(self._overlays):
+#            self.remove_overlay(overlay)
+        print("foobar")
         if self._preview:

As you can see overlay is still active after CTRL-Z of "co.py" living in directory above picamera/camera.py (that way it takes my camera.py changes and does not use installed picamera!).
Starting raspistill is no problem, and preview window appears where I ask for with "-p":
snapshot.png
snapshot.png
snapshot.png (124.34 KiB) Viewed 1085 times

It is dark here, and I don't want to disturb my hospital roommate. Official Pi display is bright enough for capturing, and my fingers get lighted by it as well ...
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 10:43 am

I been playing with HermannSW's code



install pynput with sudo pip3 install pynput

Press SPACE to take a photo, ESC to exit

Code: Select all

import time
import datetime
import picamera
import numpy as np
from PIL import Image, ImageDraw
from sys import version_info as vi
import os,sys
from pynput.keyboard import Listener, Key

def on_press(key):
    if key == Key.space:
        global camera,o,b
        camera.stop_preview()
        camera.remove_overlay(o)
        camera.close()
        now = datetime.datetime.now()
        timestamp = now.strftime("%y%m%d%H%M%S")
        fname = '/home/pi/' + str(timestamp) + '.jpg'
        path = "raspistill -o " + fname + " -t 1000"
        os.system(path)
        camera = picamera.PiCamera()
        camera.resolution = (1440, 1088)
        camera.framerate = 24
        o = camera.add_overlay(getbuffer(b), layer=3, alpha=64)
        camera.start_preview()
    elif key == Key.esc:
        camera.stop_preview()
        camera.remove_overlay(o)
        camera.close()
        sys.exit()

       
a = np.zeros((1088, 1440, 3), dtype=np.uint8)
a[360, 440:840, :] = 0xff
a[160:560, 640, :] = 0xff

i = Image.fromarray(a)
draw = ImageDraw.Draw(i)
draw.ellipse((540, 260, 740, 460), outline ='white')
b = np.asarray(i)

def getbuffer(b):
    return np.getbuffer(b) if vi.major<3 else b.tobytes()
camera = picamera.PiCamera()
camera.resolution = (1440, 1088)
camera.framerate = 24
o = camera.add_overlay(getbuffer(b), layer=3, alpha=64)
camera.start_preview()
while True:
    with Listener(on_press=on_press) as listener:
        listener.join()

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 11:54 am

...tell me what you're getting. I've packed away the RPI stuff :(

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 12:23 pm

A preview using picamera, very low lag, showing full image at 1440x1088, photo taken at full res with raspistill in about 2 secs.

Tested on v1 camera so far.

Working on adding grid.

User avatar
HermannSW
Posts: 4519
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Crosshair and grid lines

Mon Aug 02, 2021 1:37 pm

gordon77 wrote:
Mon Aug 02, 2021 12:23 pm
A preview using picamera, very low lag, showing full image at 1440x1088, photo taken at full res with raspistill in about 2 secs.
I will provide standalone overlay viewer indepent of picamera.
Idea is to run that to display grid overlay.
Then run raspistill in signal capture mode with preview (below grid).
Then any application providing gui elements.
"Take photo" button will just send signal.
Since raspistill is already running, signal will capture photo immediately.

Isn't this the way to go to avoid raspistill startup time?
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 2:17 pm

You guys may look into why raspistill is so slow, maybe it has to do with writing to the SSD.... maybe a simple RAMdisk as a buffer??

Or...maybe run raspistil and raspivid simultaneously. I tried that in the simplest possible way but got error, aparently they cant both access the camera.

Maybe raspivid + some other lib. would allow 'double access' to the camera ?

Raspivid (at full resolution) must have a full-res framebuffer somewhere we could 'tap into' to get a picture?
Last edited by Pilot65 on Mon Aug 02, 2021 2:25 pm, edited 1 time in total.

User avatar
HermannSW
Posts: 4519
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Crosshair and grid lines

Mon Aug 02, 2021 2:25 pm

Just startup time -- please try raspistill with signal or keypress option, images will get stored immediately.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 2:28 pm

HermannSW wrote:
Mon Aug 02, 2021 2:25 pm
Just startup time -- please try raspistill with signal or keypress option, images will get stored immediately.
Yeah I once tested a code snippet that took 5 pictures in a row, all appared on desktop in less than a second I think.

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 2:35 pm

HermannSW wrote:
Mon Aug 02, 2021 1:37 pm
gordon77 wrote:
Mon Aug 02, 2021 12:23 pm
.....Then run raspistill in signal capture mode with preview.....
Hmm... Seems there is more than one way to skin a cat :D
Last edited by Pilot65 on Mon Aug 02, 2021 4:18 pm, edited 1 time in total.

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 3:10 pm

Latest.. Now has a grid, adjust with L,R,U,B and K,E,Y,V keys for +/-. SPACE to run raspistill to capture photo, ESC to exit

install pynput with sudo pip3 install pynput

Raspistill signal trigger added...
Last edited by gordon77 on Wed Aug 04, 2021 4:31 pm, edited 1 time in total.

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 4:07 pm

I think these are now met, or as near as l can...

- Screen resolution should be in the range of 1-2K
-Screen FPS has high as possible, min. 5FPS
-Screen lag/latency 0-1 frame, not 1sec as we see now
-Photo resolution must be full, in my case 12MP 4056 x 3040

If HermannSW can add fom that would be great :D

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 6:29 pm

Hi tried this on the RPI3, camera window opens and I see video. But there is some KB trouble, none of the keys are working , just getting a load
of errors in the compiler. To get any kind of control I have to pull the plug and start over.
Image165464.jpg
Image165464.jpg (156.78 KiB) Viewed 858 times
Image26464.jpg
Image26464.jpg (76.77 KiB) Viewed 846 times
Image345454.jpg
Image345454.jpg (74.19 KiB) Viewed 846 times
Last edited by Pilot65 on Mon Aug 02, 2021 6:41 pm, edited 1 time in total.

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 6:32 pm

Try using idle or just python3 Cam20.py

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 6:57 pm

Neh...
Image5987987.jpg
Image5987987.jpg (182.74 KiB) Viewed 840 times
Image664594.jpg
Image664594.jpg (90.67 KiB) Viewed 837 times

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 7:02 pm

Strange, does it work until you press a key ? What about using the space bar ? What about esc ?

I have the python code in /home/pi, but not sure why that would make a difference.

I've never used pynput before, may need to look at it more.
Last edited by gordon77 on Mon Aug 02, 2021 7:13 pm, edited 1 time in total.

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 7:11 pm

No keys working, not even Esc, so I get completly stuck. Video still streaming with Xhair etc.
I once remmed out line 56 in Thonny and then Esc worked, but only once.
Last edited by Pilot65 on Mon Aug 02, 2021 7:15 pm, edited 1 time in total.

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 7:14 pm

Ctrl & Q when it stops ?

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 7:17 pm

No it doesnt respond to Ctrl Q either
KB looks normal with lights and all, also NumLock LED
Be aware of chr codes and my country/layout

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 7:53 pm

if you change the lines checking for letters from

elif key.char == 'k':

elif str(key)[1:2] == 'k':

does it help ?

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 8:36 pm

Changed
elif key.char == 'k':
to
elif str(key)[1:2] == 'k':

still not working

gordon77
Posts: 5922
Joined: Sun Aug 05, 2012 3:12 pm

Re: Crosshair and grid lines

Mon Aug 02, 2021 8:38 pm

Pilot65 wrote:
Mon Aug 02, 2021 8:36 pm
Changed
elif key.char == 'k':
to
elif str(key)[1:2] == 'k':

still not working
Did you change all the entries for all the letters ?

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 8:54 pm

6No the cerch only came yp with one incident of elif key.char == 'k':

Hang on...I'do the same for all of'em

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 9:12 pm

No still the same. Seems the keyosrd input is directed to the compiler window.
Actually not the same , keys not working, but none of those errors tis time
Wanna do ssh?

Pilot65
Posts: 53
Joined: Sat Jul 24, 2021 10:15 pm
Location: Norway

Re: Crosshair and grid lines

Mon Aug 02, 2021 10:24 pm

Some progress:
Have reinstalled pynput for python3, and changed all key checks to str(key)[1:2] as you said ...
Now there are no errors, Esc is working but gridlines and photo are not working

Edit:
Actually the vertical left may have moved, suddenly I found it at the far left edge...I held the k-key for a couple of secs and lots of autorepeat commands got cued, the whole camera window was flashing about once every sec. had to take a leak, when I came back the flickering had stopped and the line was at the far left

Return to “Camera board”