lowflyer
Posts: 78
Joined: Sat Jun 01, 2013 2:27 pm

MMAL motion with Camera V2

Thu May 05, 2016 5:13 pm

I just got my camera V2. I am happy to confirm that mmal-motion installed as per viewtopic.php?p=864996#p864996 works well with the V2 camera module in a Raspberry Pi 3B running jessie lite.

CPU usage is around 20% of one processor (so 5% of total available CPU) with the key config lines:

Code: Select all

width 640
height 480
framerate 5
mmalcam_control_params -drc --exposure night --vflip
mmalcam_use_still off
mmalcam_secondary_buffer_upscale 6
mmalcam_secondary_buffer_jpeg   50
despeckle_filter EedDl
minimum_motion_frames 5
pre_capture 4
output_secondary_pictures on
output_both_pictures on
The high resolution stills are at 3840 × 2880 and look very good. I am not sure I can see much improvement in the low light performance, but I haven't tried adjusting the parameters yet. And I still have to try NoIR V2.

I am happy :)

User avatar
jbeale
Posts: 3630
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: MMAL motion with Camera V2

Thu May 05, 2016 7:06 pm

lowflyer wrote:The high resolution stills are at 3840 × 2880 and look very good.
I am curious when you say your 8 MP stills look very good. My v2 camera shows well focused images at a distance of 30 cm, but is somewhat blurry on distant objects. Are you looking at distant outdoor scenery, or close up?

Below are crops from the same v2.1 board, with the stock lens on the left, and replaced with lens from v1.3 board on the right. Not a good comparison since several hours elapsed and light changed, but the stock lens was not as well focused.
Image

lowflyer
Posts: 78
Joined: Sat Jun 01, 2013 2:27 pm

Re: MMAL motion with Camera V2

Thu May 05, 2016 9:30 pm

@jbeale Hi!

Interesting! A lot of the picture in my first test was relatively close. Certainly leaves about 30cm away look sharp. Here is a crop with a hanging twig about 6m away which doesn't look bad, but the foliage further away does indeed look less sharp. And at the extreme right of the frame there is some evidence of blurriness and maybe chromatic aberration.
20160505164354_v2.JPG
20160505164354_v2.JPG (37.76 KiB) Viewed 15912 times
I will have a fiddle with the lenses. Has someone calculated the depth of field and hyperfocal distance?

User avatar
jbeale
Posts: 3630
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: MMAL motion with Camera V2

Thu May 05, 2016 11:32 pm

Your example doesn't look too bad, I wonder if your lens may be a bit better focused than mine was. If you look at my v2.1 PiNoIR timelapse video you will see the rising moon in the upper left hand corner starting at 0:18. It has pretty severe coma (teardrop shape instead of round).

https://www.youtube.com/watch?v=MqWwjVXQfhw

Image

lowflyer
Posts: 78
Joined: Sat Jun 01, 2013 2:27 pm

Re: MMAL motion with Camera V2

Sat May 07, 2016 5:43 pm

@jbeale I see what you mean about the coma around the moon. Is it as bad when not so overexposed? I get horrible flare on my very expensive Canon DSLR around overexposed white areas.

I managed to twist the lens in about a tenth of a turn and got a slightly better picture. And you can see some blue coma from the sky onto the tree trunk.
lastsnap_big_1_v2.jpg
lastsnap_big_1_v2.jpg (37.91 KiB) Viewed 15723 times
I guess what I meant in my first post above was that I am happy that MMAL motion works with the new camera, but not happy with the new camera itself!

energyi
Posts: 156
Joined: Tue Mar 24, 2015 9:39 pm

Re: MMAL motion with Camera V2

Sat May 07, 2016 6:52 pm

Thanks for this very informative post lowflyer! Very interested in any follow ups with NoIR V2.

energyi
energyi

User avatar
jbeale
Posts: 3630
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: MMAL motion with Camera V2

Sun May 08, 2016 3:12 am

In this outdoor shot from Pi NoIR v2 http://bealecorner.org/best/RPi/PiNoIRv2-outside.jpg you can see the roof tiles at the center of the frame (maybe 15 m away) are indeed in focus; maybe lacking only a bit of contrast and post-sharpening. Meanwhile the corners of the frame are clearly OOF.

bmikeb
Posts: 6
Joined: Wed Apr 27, 2016 8:31 am

Re: MMAL motion with Camera V2

Fri Jun 17, 2016 2:16 pm

The title of this thread is 66% of what i'm looking for. So rather than start a new thread...

I'm using MMAL motion with Camera V2, and i want an aprox 480x480 px picture of the middle 480x480 pixels.

If i set width and height to both be 480, i do get a 480x480 picture, but it's low resolution and full frame. But, I want the reverse, high resolution cropped frame.

I thought the interface did pixel binning and/or full framing ONLY if the requested aspect ratio was (or near) the standard full frame aspect ratio. Is square that close?

I have managed to get a little of what i wanted by setting the width=480 and then height=2464; or with height=1232 is also reasonable, wherewith i expect i'm getting 2x2 binning. But in these cases i'm left with 1984 (or 752) pixels of black, half on top, half on bottom - and yes, black is correct, as there is nothing there. which is precisely why i don't want it. Why stream/record/etc 2/3 wasted space.

Keeping constant my width=480 as i reduce the height from 2464 down to 1232, 1000, 900, 800... The effect i'm seeing is horizontal field of view is increasing (and resolution decreasing) with each reduction of vertical size. Which is not what i want.

Can what i'm aiming for be done?

User avatar
jbeale
Posts: 3630
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: MMAL motion with Camera V2

Fri Jun 17, 2016 6:01 pm

The cropped sub-window within the full frame that you want is done in raspistill / raspivid using the -roi a,b,c,d command line option. (ROI = Region Of Interest). I don't know what it is in motion-mmal though.

https://www.raspberrypi.org/wp-content/ ... tation.pdf

Code: Select all

--roi, -roi     Set sensor region of interest

Allows the specification of the area of the sensor to be used as the source for the preview and capture. 
This is defined as x,y for the top left corner, and a width and height, all values in normalised coordinates 
(0.0-1.0). So to set a ROI at half way across and down the sensor, and an width and height 
of a quarter of the sensor use :   -roi 0.5,0.5,0.25,0.25

lowflyer
Posts: 78
Joined: Sat Jun 01, 2013 2:27 pm

Re: MMAL motion with Camera V2

Fri Jun 17, 2016 6:34 pm

Good question @bmikeb

I have just tried mmal-motion with this in the config:

Code: Select all

mmalcam_control_params --exposure night -ISO 1600 -roi 0.5,0.5,0.25,0.25
and it does indeed limit the region of interest.

So you could see if you can find a config that does what you want. Please let us know how you get on!

Good luck!

bmikeb
Posts: 6
Joined: Wed Apr 27, 2016 8:31 am

Re: MMAL motion with Camera V2

Fri Jun 17, 2016 6:44 pm

OK, wonderful, thank you.
It will take a few days, but i will most definitely report back!

bmikeb
Posts: 6
Joined: Wed Apr 27, 2016 8:31 am

Re: MMAL motion with Camera V2

Tue Jun 21, 2016 2:09 pm

No joy...

First, i tested this, which does work:
sudo raspistill -w 400 -h 600 -t 1 -ex night -o /tmp/snap.jpg -roi 0.24,0.27,0.44,0.44

The stock original "sudo apt-get install motion" also works, but it does not recognize mmalcam_control_params; which i was not really expecting. But it does prove, that the config file (aside from 10 reports of Unknown config option) works.

So, then i ran the "motion" binary from the "motion-mmal-lowflyerUK-20151114.tar.gz" download (which, in spite of name on the tar file, has a later timestamp on the binary of Dec 19 2015)... and i connect with a web browser, and... i get grey. One even shade. Except for the timestamp in the lower right corner which dutifully changes by the second. So it is "doing" something.

I also tried running it with -n, which seems to be somewhat more informative than the log. Either with or without the -n there is this worrisome message:
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800

That "ERR" part, does seem to hint something might just be amiss, but i am clueless as to what.

Here is the output:

Code: Select all

[0] [NTC] [ALL] conf_load: Processing thread 0 - config file ./motion-mmalcam-both.conf
[0] [NTC] [ALL] motion_startup: Motion mmaltest Started
[0] [NTC] [ALL] motion_startup: Logging to syslog
[0] [NTC] [ALL] motion_startup: Using log type (ALL) log level (INF)
[0] [NTC] [ENC] ffmpeg_init: ffmpeg LIBAVCODEC_BUILD 3670272 LIBAVFORMAT_BUILD 3670272
[0] [NTC] [ALL] main: Thread 1 is from ./motion-mmalcam-both.conf
[0] [NTC] [ALL] main: Thread 1 is device: /dev/video0 input -1
[0] [NTC] [ALL] main: Stream port 8086
[1] [NTC] [ALL] motion_init: Thread 1 started , motion detection Enabled
[1] [ALR] [VID] mmalcam_start: MMAL Camera thread starting... for camera (vc.ril.camera) of 400 x 600 at 2 fps
[0] [NTC] [ALL] main: Waiting for threads to finish, pid: 8871
[1] [ALR] [VID] mmalcam_start: MMAL Camera using video capture
[0] [NTC] [STR] httpd_run: motion-httpd testing : IPV4 addr: 0.0.0.0 port: 8085
[0] [NTC] [STR] httpd_run: motion-httpd Bound : IPV4 addr: 0.0.0.0 port: 8085
[0] [NTC] [STR] httpd_run: motion-httpd/mmaltest running, accepting connections
[0] [NTC] [STR] httpd_run: motion-httpd: waiting for data on 0.0.0.0 port TCP 8085
[1] [NTC] [VID] MMAL camera component created
[1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
[1] [NTC] [STR] http_bindsock: motion-stream testing : IPV4 addr: 0.0.0.0 port: 8086
[1] [NTC] [STR] http_bindsock: motion-stream Bound : IPV4 addr: 0.0.0.0 port: 8086
[1] [NTC] [ALL] motion_init: Started motion-stream server in port 8086 auth Disabled
[1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 4 items
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [NTC] [ALL] motion_loop: fps: 1.660732 idle 0.68% over 0.21%
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
[1] [ERR] [VID] mmal_output_process_buffer: Output mmalcam - buffer size 379392 does not match destination 364800
Here is my config file (sans comments via: egrep -v '^([#;]| *$)'):

Code: Select all

daemon on
process_id_file /var/run/motion/motion.pid
setup_mode off
log_level 7
log_type all
v4l2_palette 17
input -1
norm 0
frequency 0
rotate 0
width 400
height 600
framerate 2
minimum_frame_time 0
netcam_keepalive off
netcam_tolerant_check off
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0
mmalcam_name vc.ril.camera
mmalcam_control_params --exposure night -roi 0.24,0.27,0.44,0.44
mmalcam_use_still off
mmalcam_secondary_buffer_upscale 2
mmalcam_secondary_buffer_jpeg	50
roundrobin_frames 1
roundrobin_skip 1
switchfilter off
threshold 1500
threshold_tune off
noise_level 32
noise_tune on
despeckle_filter EedDl
smart_mask_speed 0
lightswitch 0
minimum_motion_frames 2
pre_capture 2
post_capture 2
event_gap 20
max_movie_time 0
emulate_motion off
output_pictures best
output_debug_pictures off
output_secondary_pictures on
output_both_pictures on
quality 85
picture_type jpeg
ffmpeg_output_movies on
ffmpeg_output_debug_movies off
ffmpeg_output_secondary_movies off
ffmpeg_timelapse 0
ffmpeg_timelapse_mode daily
ffmpeg_bps 500000
ffmpeg_variable_bitrate 2
ffmpeg_video_codec msmpeg4
use_extpipe off
extpipe_secondary off
snapshot_interval 0
locate_motion_mode off
locate_motion_style redbox
text_right %Y-%m-%d\n%T-%q
text_changes off
text_event %Y%m%d%H%M%S
text_double off
exif_text "Test exif"
target_dir /video
snapshot_filename lastsnap
picture_filename img/%v/%v-%Y%m%d%H%M%S-%q
movie_filename %Y%m%d/%v-%Y%m%d%H%M%S
timelapse_filename %Y%m%d-timelapse
ipv6_enabled off
stream_port 8086
stream_quality 50
stream_motion off
stream_secondary off
stream_maxrate 2
stream_localhost off
stream_limit 0
stream_auth_method 0
webcontrol_port 8085
webcontrol_localhost off
webcontrol_html_output on
track_type 0
track_auto off
track_iomojo_id 0
track_step_angle_x 10
track_step_angle_y 10
track_move_wait 10
track_speed 255
track_stepsize 40
quiet on
Any help/ideas would be welcome.

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

Re: MMAL motion with Camera V2

Tue Jun 21, 2016 2:22 pm

Something funny going on there with your buffer sizes. I would advise you to stick with widths that are multiples of 32, and heights that are multiples of 16.That's what the GPU requires and will pad buffers to even if the active size is smaller. 416x608, or more normally 480x640, should work.
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.

bmikeb
Posts: 6
Joined: Wed Apr 27, 2016 8:31 am

Re: MMAL motion with Camera V2

Tue Jun 21, 2016 3:28 pm

In spite of the most excellent extremely informative and detailed error message...

We have 480x640 and Joy!

I do, recall an x8 requirement (hence 400=50x8, 600=75x8), but nothing about x32 and x16.

My i suggest that raspistill (and it's friends) produce perhaps a friendly warning message when a user has strayed from the path of true righteousness that a non-standard (x*32,y*16) may yield unexpected results. Or maybe just that the man page (and particularly the run-time --help) mention the requirement. That would elevate this to true feature status!

And without any sarcasm...
Thank you jbeale, lowflyer, and 6by9

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

Re: MMAL motion with Camera V2

Tue Jun 21, 2016 3:53 pm

bmikeb wrote:In spite of the most excellent extremely informative and detailed error message...

We have 480x640 and Joy!

I do, recall an x8 requirement (hence 400=50x8, 600=75x8), but nothing about x32 and x16.

My i suggest that raspistill (and it's friends) produce perhaps a friendly warning message when a user has strayed from the path of true righteousness that a non-standard (x*32,y*16) may yield unexpected results. Or maybe just that the man page (and particularly the run-time --help) mention the requirement. That would elevate this to true feature status!

And without any sarcasm...
Thank you jbeale, lowflyer, and 6by9
Raspistill etc do do the correct thing if you ask for a weird size - they should accept any even number (chroma subsampling gets weird if you have an odd number).
MMAL motion is not one of the main supported apps - I'm not going debugging it.

It has told you what the fault is
"buffer size 379392 does not match destination 364800"
Motion MMAL passed in a buffer of size 379293 bytes when the system was expecting 364800. That means the code in motion MMAL is picking up something weird in order to produce the buffer size. I would expect 416x608 * 1.5 = 379392. 364800 seems to be 608x400 * 1.5, but where have those numbers come from? Something has probably got the padding restrictions wrong.
MMAL will tell you the correct size buffer that it needs, and expects to get it.
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.

Return to “Camera board”