OpenCV "no support for memory mapping"--any workarounds?

2023-07-11 Thread Jeff Ross

Hi all,

Trying to run an OpenCV python script on a Raspberry Pi 4 with 7.3 and 
4G of ram with a single 2K webcam.


I'm getting this when I try to set the camera to shoot at 2K resolution 
(1920px x 1080px):


capture is open...
[ WARN:0@2.098] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:847 requestBuffers 
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:847 requestBuffers 
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers 
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:847 requestBuffers 
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
FPS: 30.303, Height: 480.0, Width: 640.0, Exp: auto, Gain: auto, 
AutoExp: -1.0, Frames: 3


Requested 1920 x 1080 and got 640 x 480.

I had a similar issue before with an amd64 stick:

https://marc.info/?l=openbsd-ports&m=162862043308236&w=2

This is OpenCV installed from packages:

jross@allsky:/home/jross $ pkg_info opencv
Information for inst:opencv-4.7.0

It would seem then that this problem isn't going away any time soon but 
if someone has a workaround I'd love to hear it.


I had hoped to use the RPi4 to drive 5 of these 2K webcams to make an 
allsky camera.


I have an amd64 with 16G of ram that I'll try next just in case there's 
a big difference between amd64 and arm64.


Jeff

dmesg:

jross@allsky:/home/jross $ dmesg
OpenBSD 7.3 (GENERIC.MP) #2080: Sat Mar 25 14:20:25 MDT 2023
dera...@arm64.openbsd.org:/usr/src/sys/arch/arm64/compile/GENERIC.MP
real mem  = 4124950528 (3933MB)
avail mem = 3963645952 (3780MB)
random: good seed from bootblocks
mainbus0 at root: Raspberry Pi 4 Model B Rev 1.5
cpu0 at mainbus0 mpidr 0: ARM Cortex-A72 r0p3
cpu0: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu0: 1024KB 64b/line 16-way L2 cache
cpu0: CRC32,ASID16
cpu1 at mainbus0 mpidr 1: ARM Cortex-A72 r0p3
cpu1: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu1: 1024KB 64b/line 16-way L2 cache
cpu1: CRC32,ASID16
cpu2 at mainbus0 mpidr 2: ARM Cortex-A72 r0p3
cpu2: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu2: 1024KB 64b/line 16-way L2 cache
cpu2: CRC32,ASID16
cpu3 at mainbus0 mpidr 3: ARM Cortex-A72 r0p3
cpu3: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu3: 1024KB 64b/line 16-way L2 cache
cpu3: CRC32,ASID16
efi0 at mainbus0: UEFI 2.8
efi0: Das U-Boot rev 0x20211000
smbios0 at efi0: SMBIOS 3.0
smbios0: vendor U-Boot version "2021.10" date 10/01/2021
smbios0: Unknown Unknown Product
apm0 at mainbus0
"system" at mainbus0 not configured
"axi" at mainbus0 not configured
simplebus0 at mainbus0: "soc"
bcmclock0 at simplebus0
bcmmbox0 at simplebus0
bcmgpio0 at simplebus0
bcmaux0 at simplebus0
ampintc0 at simplebus0 nirq 256, ncpu 4 ipi: 0, 1, 2: "interrupt-controller"
bcmtmon0 at simplebus0
bcmdmac0 at simplebus0: DMA0 DMA2 DMA4 DMA5 DMA6 DMA7 DMA8 DMA9 DMA10
"timer" at simplebus0 not configured
pluart0 at simplebus0: rev 2, 16 byte fifo
pluart0: console
"local_intc" at simplebus0 not configured
bcmdog0 at simplebus0
bcmirng0 at simplebus0
"firmware" at simplebus0 not configured
"power" at simplebus0 not configured
"mailbox" at simplebus0 not configured
sdhc0 at simplebus0
sdhc0: SDHC 3.0, 250 MHz base clock
sdmmc0 at sdhc0: 4-bit, sd high-speed, mmc high-speed
"gpiomem" at simplebus0 not configured
"fb" at simplebus0 not configured
"vcsm" at simplebus0 not configured
"clocks" at mainbus0 not configured
"phy" at mainbus0 not configured
"clk-27M" at mainbus0 not configured
"clk-108M" at mainbus0 not configured
simplebus1 at mainbus0: "emmc2bus"

Re: OpenCV "no support for memory mapping"--any workarounds?

2023-07-11 Thread Stuart Henderson
This is the message printed by CvCaptureCAM_V4L::requestBuffers when the 
ioctl fails with EINVAL.


For uvideo the backend to this is uvideo_reqbufs() in /sys/dev/USB/uvideo.c 
- this has several cases which return EINVAL. Did you get any kernel 
messages (dmesg, /var/log/messages) while it was reporting these "no 
support for memory mapping" errors?


If not, you can differentiate between some of these EINVAL by building a 
kernel with "#define UVIDEO_DEBUG" added to uvideo.c (before the #ifdef 
UVIDEO_DEBUG), which might give some clues about what your Python code is 
doing that didn't work with openbsd's v4l2 implementation.


But...if my quick calculations are right, reading and processing at that 
resolution in colour is about 6MByte per frame, so 5 channels at say 8fps 
would be in the region of ~240MByte/s (~2Gbit/s). Even if you can get the 
code working with openbsd, I really think you are going to struggle to read 
that from USB and run image processing on the data on a Pi 4 running 
openbsd (also openbsd's USB layer is not known for being particularly 
reliable). I think this task is better suited to running under Linux.


--
 Sent from a phone, apologies for poor formatting.

On 11 July 2023 22:12:37 Jeff Ross  wrote:


Hi all,

Trying to run an OpenCV python script on a Raspberry Pi 4 with 7.3 and
4G of ram with a single 2K webcam.

I'm getting this when I try to set the camera to shoot at 2K resolution
(1920px x 1080px):

capture is open...
[ WARN:0@2.098] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.115] global cap_v4l.cpp:847 requestBuffers
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.131] global cap_v4l.cpp:847 requestBuffers
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:868 requestBuffers
VIDEOIO(V4L2:/dev/video0): no support for memory mapping
[ WARN:0@2.154] global cap_v4l.cpp:847 requestBuffers
VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
FPS: 30.303, Height: 480.0, Width: 640.0, Exp: auto, Gain: auto,
AutoExp: -1.0, Frames: 3

Requested 1920 x 1080 and got 640 x 480.

I had a similar issue before with an amd64 stick:

https://marc.info/?l=openbsd-ports&m=162862043308236&w=2

This is OpenCV installed from packages:

jross@allsky:/home/jross $ pkg_info opencv
Information for inst:opencv-4.7.0

It would seem then that this problem isn't going away any time soon but
if someone has a workaround I'd love to hear it.

I had hoped to use the RPi4 to drive 5 of these 2K webcams to make an
allsky camera.

I have an amd64 with 16G of ram that I'll try next just in case there's
a big difference between amd64 and arm64.

Jeff

dmesg:

jross@allsky:/home/jross $ dmesg
OpenBSD 7.3 (GENERIC.MP) #2080: Sat Mar 25 14:20:25 MDT 2023
dera...@arm64.openbsd.org:/usr/src/sys/arch/arm64/compile/GENERIC.MP
real mem  = 4124950528 (3933MB)
avail mem = 3963645952 (3780MB)
random: good seed from bootblocks
mainbus0 at root: Raspberry Pi 4 Model B Rev 1.5
cpu0 at mainbus0 mpidr 0: ARM Cortex-A72 r0p3
cpu0: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu0: 1024KB 64b/line 16-way L2 cache
cpu0: CRC32,ASID16
cpu1 at mainbus0 mpidr 1: ARM Cortex-A72 r0p3
cpu1: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu1: 1024KB 64b/line 16-way L2 cache
cpu1: CRC32,ASID16
cpu2 at mainbus0 mpidr 2: ARM Cortex-A72 r0p3
cpu2: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu2: 1024KB 64b/line 16-way L2 cache
cpu2: CRC32,ASID16
cpu3 at mainbus0 mpidr 3: ARM Cortex-A72 r0p3
cpu3: 48KB 64b/line 3-way L1 PIPT I-cache, 32KB 64b/line 2-way L1 D-cache
cpu3: 1024KB 64b/line 16-way L2 cache
cpu3: CRC32,ASID16
efi0 at mainbus0: UEFI 2.8
e

Re: OpenCV "no support for memory mapping"--any workarounds?

2023-07-12 Thread Jeff Ross

On 7/11/23 11:55 PM, Stuart Henderson wrote:
This is the message printed by CvCaptureCAM_V4L::requestBuffers when 
the ioctl fails with EINVAL.


For uvideo the backend to this is uvideo_reqbufs() in 
/sys/dev/USB/uvideo.c - this has several cases which return EINVAL. 
Did you get any kernel messages (dmesg, /var/log/messages) while it 
was reporting these "no support for memory mapping" errors?


If not, you can differentiate between some of these EINVAL by building 
a kernel with "#define UVIDEO_DEBUG" added to uvideo.c (before the 
#ifdef UVIDEO_DEBUG), which might give some clues about what your 
Python code is doing that didn't work with openbsd's v4l2 implementation.


But...if my quick calculations are right, reading and processing at 
that resolution in colour is about 6MByte per frame, so 5 channels at 
say 8fps would be in the region of ~240MByte/s (~2Gbit/s). Even if you 
can get the code working with openbsd, I really think you are going to 
struggle to read that from USB and run image processing on the data on 
a Pi 4 running openbsd (also openbsd's USB layer is not known for 
being particularly reliable). I think this task is better suited to 
running under Linux.


--
  Sent from a phone, apologies for poor formatting.


On 11 July 2023 22:12:37 Jeff Ross  wrote:


Hi all,

Trying to run an OpenCV python script on a Raspberry Pi 4 with 7.3 and
4G of ram with a single 2K webcam.


Thanks as always Stuart.

I'll be stacking 20-30 half second exposures for the all sky cameras but 
I didn't know about the USB layer reliability issue.


The amd64 rig will be a better fit for this project.

Jeff