You are not logged in.

#1 2021-04-16 20:01:52

throbscottle
Member
Registered: 2011-11-05
Posts: 55

Webcam perspective control?

I'm using a boroscope/endoscope bought off Banggood to target a pcb drill, using guvcview, with a crosshair overlaid with qiv. It works very well, the main caveat being the camera is mounted to one side so everything is trapezoid.

It would be very helpful if I can make it look more vertical than it is - ie some sort of perspective adjustment in the live view. Is there a way to do this?

Thanks in advance...

Offline

#2 2021-04-17 03:05:12

mpan
Member
Registered: 2012-08-01
Posts: 1,207
Website

Re: Webcam perspective control?

No idea about guvcview, but you may use the perspective filter from ffmpeg, sourcing the video directly through v4l2.

ffplay -f v4l2 …format options… -i /dev/video0 -vf 'perspective=0:0:W:0:-60:H:670:H'

You may find the exact cöordinates using Gimp and it’s perspective correction tool in the “Corective (backward)” mode. Those are the same values as the handles use (displayed in the status bar of the window; not the transformation values in the subwindow).

Documentation for the format options for ffmpeg and how to obtain them is ffmpeg webcam docs.

An example showing the raw image on top and one corrected with “0:0:W:0:-60:H:670:H” on the bottom.

Last edited by mpan (2021-04-17 03:07:44)


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#3 2021-04-17 06:18:09

progandy
Member
Registered: 2012-05-17
Posts: 5,191

Re: Webcam perspective control?

This document has some ffmpeg tricks and shows how to create crosshairs on page 137. You can combine it with the perspective filter and have a live view.
http://www.astro-electronic.de/FFmpeg_Book.pdf

Edit: Here is an example

ffmpeg -fflags nobuffer -flags low_delay -avioflags direct -f v4l2 -video_size 1280x720 -framerate 5 -pixel_format mjpeg -i /dev/video0 -lavfi "perspective=0:0:W:0:-60:H:670:H,format=rgb24,drawbox=x=iw/2:y=0:w=1:h=ih/2-10:color=yellow,drawbox=x=iw/2:y=ih/2+10:w=1:h=ih/2-10:color=yellow,drawbox=x=0:y=ih/2:w=iw/2-10:h=1:color=yellow,drawbox=x=iw/2+10:y=ih/2:w=iw/2-10:h=1:color=yellow,format=rgb24" -window_x 0 -window_y 0 -f sdl2 -

Last edited by progandy (2021-04-17 06:45:13)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#4 2021-04-17 10:54:29

throbscottle
Member
Registered: 2011-11-05
Posts: 55

Re: Webcam perspective control?

Wow - ffmpeg has been sitting there all this time, but since I don't do video, I simply never thought of it! Will definitely give that a try.

The cross-hair is nice - but dependent on the work-piece being always at the same height. I'll have a play with it. How hard would it be to implement a live positioning control? Would only need to move maybe 20px once the normal position is sorted out.

Offline

#5 2021-04-17 13:41:04

progandy
Member
Registered: 2012-05-17
Posts: 5,191

Re: Webcam perspective control?

If you need a movable crosshair, you'd have to script that. Maybe you can use https://github.com/cyanreg/txproto , then implement some way to change the position of the drawbox filters.
It should also be possible to send commands to the drawbox filters with zeromq, but the arch ffmpeg is compiled without zeromq support. (You could try ffmpeg-full from the AUR)

Last edited by progandy (2021-04-17 13:45:49)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2021-04-17 18:05:06

throbscottle
Member
Registered: 2011-11-05
Posts: 55

Re: Webcam perspective control?

Hmm, something to look at when I'm not drilling holes, then... Meanwhile qiv is doing the cross-hair job quite well!

Thanks for the help, the example you gave for perspective is pretty close to what I need - good guess!

Offline

#7 2023-09-01 19:48:27

throbscottle
Member
Registered: 2011-11-05
Posts: 55

Re: Webcam perspective control?

Finally, I managed to actually test this!
Just to update - it turned out I needed to change the Y positions since the camera is off to the side. Set up using graph paper, got the image pretty "flat".  Works really well, perfect target!
Thank you very much smile

Offline

Board footer

Powered by FluxBB