rayzrocket
Posts: 3
Joined: Tue Jul 30, 2019 4:57 pm

Re: Raw sensor access / CSI-2 receiver peripheral

Thu Aug 15, 2019 11:08 pm

I can't wait to get some C code running using the CSI-2 raspicamV2. For now my skills limit me to basic Python.
My Python3 code with CV2 frame capture on a USB camera and Numpy array manipulation running in Thonny IDE....
Track algo of Minimum sum:
2ms / 25 pixel wide area
9ms / 90 pixel wide area
12ms / 100 pixel wide area
15ms / 115 pixel wide area
20ms / 140 pixel wide area

Placing text on the frame = 2 to 3 ms
Read 25 bytes on Pi serial input @ 100kbaud = 3ms
Parse SBUS protocol into useful values = <1ms
Send out 25 bytes = 3ms
cv2.imshow (show the image on the screen) = <5ms
I sent you email of my algo and code since it's a bit large for the forum.

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

Re: Raw sensor access / CSI-2 receiver peripheral

Fri Aug 16, 2019 12:38 pm

Found this tweet from @MachinePix:
Removing unripe tomatoes with an optical sorter.
https://twitter.com/MachinePix/status/9 ... 5057209344

Not sure what optical sensors are used, nor have any information on the framerate in case it is a/are camera(s).
This is just small clip from slow motion part of the tweet's video, raspiraw should be able to provide support for the same functionality:
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

lak4cyut
Posts: 2
Joined: Wed Aug 21, 2019 6:27 am

Re: Raw sensor access / CSI-2 receiver peripheral

Wed Aug 21, 2019 9:30 am

6by9 wrote:
Thu May 30, 2019 9:46 am
The main ones:
- Licence. Any kernel driver almost has to be GPLv2 and therefore open source. Check with your sensor supplier that they are happy for the register set to be released. Copying raspiraw means that the register set can be hidden in your userspace app which can be under any licence you fancy (including closed). It's all a little silly as it is trivial to put an I2C analyser on the lines to the camera module, run your app, and capture the relevant commands.
- Framework. V4L2 is the Linux standard APIs and is therefore portable to other platforms. MMAL is specific to the Pi.
- Support. I'm less inclined to fix any issues discovered in rawcam than in V4L2. V4L2 is seen as the way forward.
rcasiodu wrote:In the first method, can you give me an example of drive file? Could I just modify the ov5647.c(/drivers/media/i2c/ov5647.c) to other sensor?
/drivers/media/i2c/ov5647.c is a relatively basic driver, but would work. imx258.c is a little more comprehensive, but lacks the dt/fwnode configuration and regulator control (not essential if you set the power control GPIO some other way). I believe ov5640.c is a reasonable example of that.
rcasiodu wrote:How to use the v4l2 driver to get raw data from sensor? Is it possible to transfer raw10/raw12 to yuv data?(use arm core?)
You use the V4L2 API to get raw frames out.
"v4l2-ctl --stream--map=3 --stream-to=foo.raw --stream-count=100" would be a simple existing tool.
https://linuxtv.org/downloads/v4l-dvb-a ... ure.c.html is the standard example for grabbing frames. Do what you want in process_image(). You want to be using the MMAP method, not read (userptr isn't supported).
Hi 6by9,
Thanks for your information.
I built a custom kernel to enable bcm2835-unicam and ov5647 kernel modules and add ov5647 dt overlay, try to capture camera image via V4L2 official interface. (Of course I bought a Raspberry Pi official camera module - OV5647 version.)
And use v4l2-ctl to capture image.

Code: Select all

v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1
But the captured image is abnormal (overlay & distortion) (I put the image below).
Would you like to provide me some hint about how to debug this problem? Or do you know what caused it.
It drive me crazy...

Thanks for the help.
frame2.jpg
frame2.jpg (79.79 KiB) Viewed 239 times
frame.jpg
frame.jpg (122.32 KiB) Viewed 239 times
Detail info:
Kernel base version: 4.19.64
Raspberry Pi: 3 model B v1.2
Camera Module: Raspbery Pi (OV5647) Rev 1.3

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

Re: Raw sensor access / CSI-2 receiver peripheral

Thu Aug 22, 2019 10:34 am

lak4cyut wrote:
Wed Aug 21, 2019 9:30 am
Hi 6by9,
Thanks for your information.
I built a custom kernel to enable bcm2835-unicam and ov5647 kernel modules and add ov5647 dt overlay, try to capture camera image via V4L2 official interface. (Of course I bought a Raspberry Pi official camera module - OV5647 version.)
And use v4l2-ctl to capture image.

Code: Select all

v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.raw --stream-count=1
But the captured image is abnormal (overlay & distortion) (I put the image below).
Would you like to provide me some hint about how to debug this problem? Or do you know what caused it.
It drive me crazy...

Thanks for the help.
Duplicate of https://www.raspberrypi.org/forums/view ... 2#p1522892, therefore I'm not responding here (it's not relevant to rawcam).
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.

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

Re: Raw sensor access / CSI-2 receiver peripheral

Thu Aug 22, 2019 11:29 pm

@6by9 I want to play with my new 4GB Pi4B and raspiraw.
v2 camera works with raspivid on Pi4B.
I did clone latest raspiraw from your repo, because that knows about Pi4B.
But camera shows up as /dev/i2c-1 and not /dev/i2c-0.
I did change camera_i2c last line in 4B section to "i2cdetect -y 1" because of that.
But it shows no connected device, just double dashes everywhere.
I added "-y 1" to raspiraw call in tools/640x128, but the command fails as well.

Is this a Buster does not like raspiraw thing?
What do I need to change/do differently in order to get raspiraw working on Pi4B?
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: Raw sensor access / CSI-2 receiver peripheral

Fri Aug 23, 2019 7:05 am

Sorry, my fault, I only enabled I2C in raspi-config and missed to add "dtparam=i2c_vc=on" to "/boot/config.txt".
Now raspiraw works, but I get two super huge frame skips when running 640x128 tool, investigating:

Code: Select all

[email protected]:~/raspiraw/c $ 640x128 2000
removing /dev/shm/out.*.raw
capturing frames for 2000ms with 349fps requested
495 frames were captured at 351fps
frame delta time[us] distribution
      1 -9223372036854775808
      1 
      3 0
      1 2839
      1 2841
      3 2842
    339 2843
    124 2844
      1 2848
      1 5686
      1 5687
      1 14218
      1 19903
      1 22746
      1 22747
      2 25589
      2 25590
      3 28432
      1 28433
      1 36963
      2 51179
      2 54022
      1 105201
      1 9223372036723459902
after skip frame indices (middle column)
5686,2,129328465
19903,3,129348368
54022,7,129482001
51179,8,129533180
105201,9,129638381
51179,11,129717992
54022,12,129772014
36963,16,129888588
14218,17,129902806
5687,139,130317921
9223372036723459902,491,-9223372036854775808
2% frame skips
[email protected]:~/raspiraw/c $

"head" looks fine:

Code: Select all

[email protected]:~/raspiraw/c $ head -3 tstamps.csv 
,1,129322779
5686,2,129328465
19903,3,129348368
[email protected]:~/raspiraw/c $

But "tail" looks ugly:

Code: Select all

[email protected]:~/raspiraw/c $ tail -6 tstamps.csv 
2844,490,131315906
9223372036723459902,491,-9223372036854775808
-9223372036854775808,492,0
0,493,0
0,494,0
0,495,0
[email protected]:~/raspiraw/c $ 



This is all to get raspiraw running:

Code: Select all

[email protected]:~ $ cat /etc/modules-load.d/modules.conf 
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

i2c-dev
[email protected]:~ $ 

Code: Select all

[email protected]:~/raspiraw/c $ grep i2c /boot/config.txt 
dtparam=i2c_arm=on
dtparam=i2c_vc=on
[email protected]:~/raspiraw/c $ 
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”