Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Image Overlay OpenCV

Sat Nov 16, 2019 1:27 am

ok so ive successfully installed opencv but i cant find a open source code to finalize my project.

Basically im trying to make a pair of nv goggles/sniper scope with an overlay.

can anyone help me?
Attachments
Reticle.jpg
Reticle.jpg (13.22 KiB) Viewed 560 times

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

Re: Image Overlay OpenCV

Sat Nov 16, 2019 4:43 am

C++: https://answers.opencv.org/question/187 ... -opencv-c/
Python: https://stackoverflow.com/questions/140 ... 4#14102014

P.S:
I already have alpha blending sample in my "bash i420toh264 pipeline" for on the fly Raspberry video processing while recording:
https://github.com/Hermann-SW2/userland ... a-blending
Overlaying image is not that difficult there too, just has to be split over the Y, U and V blocks.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Re: Image Overlay OpenCV

Sat Nov 16, 2019 4:57 am

HermannSW wrote:
Sat Nov 16, 2019 4:43 am
C++: https://answers.opencv.org/question/187 ... -opencv-c/
Python: https://stackoverflow.com/questions/140 ... 4#14102014

P.S:
I already have alpha blending sample in my "bash i420toh264 pipeline" for on the fly Raspberry video processing while recording:
https://github.com/Hermann-SW2/userland ... a-blending
Overlaying image is not that difficult there too, just has to be split over the Y, U and V blocks.
This isn't really what i meant since those just seem to overlay on a static image and the others use either a face tracking feature or its tracking a plane but what i meant was to just overlay the image using the live camera feed and have it just boot to the script upon activation.

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

Re: Image Overlay OpenCV

Sat Nov 16, 2019 6:18 am

Church Lenard wrote:
Sat Nov 16, 2019 4:57 am
This isn't really what i meant since those just seem to overlay on a static image and the others use either a face tracking feature or its tracking a plane but what i meant was to just overlay the image using the live camera feed and have it just boot to the script upon activation.
I am sure that can be done in OpenCV, though OpenCV will add latency to the video stream.

I just added reticle example (fine crosshair) to (high performance) "bash i420toh264 pipeline" repo.
Fine crosshair will be overlaid onto every frame and is part of GPU generated .h264 video:
https://github.com/Hermann-SW2/userland ... nt-reticle
Image

All that is needed to use your Reticle.jpg is to store it as .pgm image:

Code: Select all

$ echo -e "P5\n1640 922\n255\n" >white.pgm
$ head --bytes $((1640*922)) /dev/zero | sed "s/\x00/\xFF/g" >>white.pgm
$ jpegtopnm Reticle.jpg > Reticle.pnm
jpegtopnm: WRITING PPM FILE
$ pnmcomp -align=center -valign=middle Reticle.pnm white.pgm | ppmtopgm > Reticle.pgm
$ 
If you store the generated .h264 video into a named pipe, you could use "/opt/vc/src/hello_pi/hello_video/hello_video.bin" to play live video with reticle overlay on monitor:
https://github.com/Hermann-SW2/userland ... a-blending
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Re: Image Overlay OpenCV

Sat Nov 16, 2019 8:06 am

OK ill try that tomorrow as it is 2:30 am where i am ill let you know how it goes

Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Re: Image Overlay OpenCV

Sat Nov 16, 2019 5:33 pm

for the execution part it sais "no such file or directory" for./i420toh264

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8093
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Image Overlay OpenCV

Sat Nov 16, 2019 5:41 pm

Do you need the overlay on an encoded stream of some form, or just on the HDMI display?
If the latter then just add an extra overlay using either the DispmanX API, or MMAL video_render component. PiCamera provides a simple API for adding an extra overlay, and should work even if you're not using PiCamera for driving the camera. See https://picamera.readthedocs.io/en/late ... he-preview for details.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Re: Image Overlay OpenCV

Sat Nov 16, 2019 5:59 pm

6by9 wrote:
Sat Nov 16, 2019 5:41 pm
Do you need the overlay on an encoded stream of some form, or just on the HDMI display?
If the latter then just add an extra overlay using either the DispmanX API, or MMAL video_render component. PiCamera provides a simple API for adding an extra overlay, and should work even if you're not using PiCamera for driving the camera. See https://picamera.readthedocs.io/en/late ... he-preview for details.
just tried the sample codes they had and neither would draw or display anything it would only show the camera feed.

also im just trying to make a overlay script that doesn't record or capture images just shows the camera feed with the overlay on an hdmi lcd screen

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

Re: Image Overlay OpenCV

Sat Nov 16, 2019 6:37 pm

Are you trying to do the same as previously?

https://www.raspberrypi.org/forums/view ... p?t=239466

Church Lenard
Posts: 34
Joined: Wed May 01, 2019 4:45 pm

Re: Image Overlay OpenCV

Sat Nov 16, 2019 6:47 pm

gordon77 wrote:
Sat Nov 16, 2019 6:37 pm
Are you trying to do the same as previously?

https://www.raspberrypi.org/forums/view ... p?t=239466
correct but i had thought that topic had died out since it took me almost a year to compile opencv and it turns out the make -j4 command was the culprit

Return to “Camera board”