Camera using OpenMAX

Anything and everything about programming graphics with Ultibo
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Camera using OpenMAX

Postby pik33 » Mon Oct 15, 2018 7:37 pm

No, I didn't do anything like a screen capture, but it is of course possible to do.

There should be a big red raspberry at the center of the screen. It is loaded from a bitmap in (boot)\Colors\Wallpapers directory. If there is no Colors\Wallpapers\rpi-logo.rbm there, then you will get a garbage filled rectangle on the center of the screen, which comes from an uninitialized memory after fileread failed (I didn't do the error checking there)

Copy the Colors directory from the project directry to the root of the boot partition, if you didn't do this yet. Without this the RetAMP player will also be black or garbage filled as the skins for RetAMP also reside there.
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Camera using OpenMAX

Postby mark » Wed Oct 17, 2018 8:48 pm

vnc 1.tcp.ngrok.io::22591 implements branch https://github.com/markfirmware/ultibo_ ... st-amazing

I added the current vnc 3.3 files and now have to just copy pixels from the camera buffer to the vnc canvas.

Piotr, uVNCCamera.pas is the file that I need to change. It is in a one-second loop updating text and now it needs to move some pixels.

Regards,
Mark

p.s. based on https://github.com/markfirmware/VNC/tree/rpi3 - will merge that branch back to master when I finish completing the multi-target rpi/rpi2/rpi3/qemu code.
pjde
Posts: 438
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Camera using OpenMAX

Postby pjde » Thu Oct 18, 2018 12:53 am

This is what I get.

Updates about once a second

Regards

Paul
Attachments
vnc1.png
vnc1.png (20.5 KiB) Viewed 676 times
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Camera using OpenMAX

Postby pik33 » Thu Oct 18, 2018 9:52 am

Piotr, uVNCCamera.pas is the file that I need to change. It is in a one-second loop updating text and now it needs to move some pixels.


In my camera code main loop:

Code: Select all

OMX_FillThisBuffer(mContext.pCamera, mContext.pBufferCameraOut);
scale4c(y2,cardinal(miniwindow.canvas),cyres div 4,cxres) ;
fastmove(y2,cardinal(rendertestwindow.canvas),cxres*cyres);


OMX_FillThisBuffer initiates filling the camera buffer. This buffer was allocated earlier in the code and then the variable y2 was calculated.
y2 points to Y (intensity) pixels in the camera buffer.
What I am doing with these pixels is calling fastmove, which is a fast asm procedure which moves these bytes to the (bigger) window canvas
I also call scale4c which gets every 4th pixel in every 4th line and transfer these to the canvas of the smaller window.

Now my canvases are 8bit so I only needed to transfer raw data from the camera Y buffer and set a grayscale pallette.
I suppose you have 32-bit canvas, and this will complicate things a bit because you have to translate 8 bit grayscale (or 8 bit YUV if you want to have colors) to 32-bit.

So you will need something like scale4c, modified like this:

Code: Select all

procedure scale4c(from,too,lines,bpl:integer);

// --- rev 20181014


label p101,p102;

begin


                  asm
                  push {r0-r12}
                  ldr r0,from
                  ldr r1,too
                  ldr r2,lines
                  ldr r3,bpl

p102:             mov r7,r3

p101:             mov r12,#0

                  ldrb r6,[r0],#4
                 
                  // ---------------------------------modification here:
                  add r6,r6,r6,lsl #8
                  add r6,r6,r6,lsl #16
                  lsr r6,#8
                 
                  str r6,[r1],#4
                 
                  ----------------------------------end of modification

                  subs r7,#4
                  bgt  p101

                  add r0,r0,r3
                  add r0,r0,r3
                  add r0,r0,r3

                //  sub r0,#4

                  subs r2,#1
                  bgt p102
                  pop {r0-r12}
                  end;
end;



If I didn't make any mistakes modifying this offline, this should convert 000000xx in R6 to 00xxxxxx which then will give you a grayscale picture on 32-bit canvas

If the project which I started will be continued I will need this (sending the camera data over VNC) too :) but now I am working on analyzing this data FAST to find light spots.
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Camera using OpenMAX

Postby mark » Sat Oct 20, 2018 1:00 am

Thanks Piotr and Paul. I was able to get the 320x180 gray over rgb working before I left the lab. Need to make retro gui start the camera on start up and not stop after 600 seconds. It is not on-line now but hopefully tomorrow we will see the train on vnc on the internet. Mark.
pik33
Posts: 852
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: Camera using OpenMAX

Postby pik33 » Sat Oct 20, 2018 6:50 am

Need to make retro gui start the camera on start up and not stop after 600 seconds.


You can find the main GUI loop in the Project1.pas. You have to copy this

Code: Select all

  if cameratest.dblclicked then
    begin
    cameratest.dblclicked:=false;
    if keypressed then readkey;
    if cmw=nil then
      begin
      camerathread:=TCameraThread.create(true);
      camerathread.start;
      cmw:=camerathread;
      end;
end;


remove the conditional instruction and place this:

Code: Select all

    if keypressed then readkey;
    if cmw=nil then
      begin
      camerathread:=TCameraThread.create(true);
      camerathread.start;
      cmw:=camerathread;
      end;
 


before the main loop. This will clear the keyboard buffer and start the camera thread.

To change how long it will work when started, you have to change

Code: Select all

nFrameMax:= mContext.nFramerate * 600;


in camera1.unit. Now it is 600xframerate so the camera works for 600 seconds and stops. Change it to what you want.

This line

Code: Select all

while(nFrames < nFrameMax) and (not keypressed) do


controls the main camera loop so if you leave only keypressed, then the camera will not stop untill you press any key.
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Camera using OpenMAX

Postby mark » Sun Oct 21, 2018 1:11 am

Thanks Piotr - the automatic start seemed to work sometimes but other times there was a camera error in the log when starting. I added a three second delay just before starting the camera and that seemed to produce a reliable result. I will work again on Monday to get the train displayed on the internet. Thanks, Mark.
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Camera using OpenMAX

Postby mark » Fri Dec 21, 2018 1:14 am

pjde wrote:Should stick to the KISS approach.

Have managed to get a basic version of the camera as a video source going using OpenMAX IL and native pascal.

Have added it to the https://github.com/pjde-ultibo/openmax repository.

Have to add
start_x=1
gpu_mem=128

to your config.txt file.

Enjoy

Paul


https://github.com/markfirmware/ultibo- ... /v20181221

The kernel sampler now includes the Camera.lpr kernel. Mark.

EDIT: FYI the changes needed to add it to the sampler are https://github.com/markfirmware/ultibo- ... d66515cec0
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Camera using OpenMAX

Postby mark » Wed Jan 16, 2019 9:14 pm

https://github.com/markfirmware/prototy ... camera-tcp

Uses Piotr's simple camera and Paul's omx units to stream to a host Lazarus program. This repo should work but its primary purpose is to retain the useable work that I've done over the last four weeks. There is no release and anyone interested will need to build with both host and ultibo Lazarus and also create a useable sd card file by file.

Mark

Return to “Graphics”

Who is online

Users browsing this forum: No registered users and 1 guest