Raspberry Pi 3 camera control

I need to run a desktop application on a Raspberry Pi 3 with a camera moule
I need to see a preview of the camera inside a canvas and place a button to take still pictures.
Anyone already did that and could share me some code ?
Thanks

I found an old RB class that seem to be what I need but it uses some old Quick Time Libraries.
The name of the class that is REAL CAPTURE CANVAS and It is free but with no support at all now.
http://sonicamigos.com/realcapture/
I had downloaded examples and the class but it uses QuickTimeLib that I assume it belongs to Quick Time 7.
Any idea to how to replace this Library ???
Thanks.

I do not know of any classes or plugins for this but maybe this can help xdevlibrary

There is a new book Program Raspberry Pi 2 B Electronics with Xojo and the Table Of Contents for Chapter 11 is on the camera.

Hope this helps :smiley:

We may need to check what c API does control camera.
Maybe I can write a plugin for this.

You need to use “raspicam” commandline tool with the shell class.

I bought the book from the xdevlibrary, but did not solve my problem.
Nice book but nothing that i didnt know before, at least related to the camera module.

It will be VERY interesting if Cristian could develop a plugin with two main features:

  • Preview the camera in a control
  • Take a snapshot of the preview and save it to a file
    I understand that the most interesting possibilities of the RPi asociated to the XoJo developmet language are the GPIO and the camera. So a pluging (for desktop and web) that let easily control the camera would be a very nice and usefull contribution. I will be the first customer and I suppose that it would be a succesfull commercial pluging. I hope you could do it Cristian !!!

Why not just use a Shell like Derk said? It’s not hard at all. The web is full of Pi tutorials that fo exactly what you ask and you simply wrap the calls to the Shell.

Gavin, I beleive that you didn’t understand my need.
I need to have a canvas control like, in a window of a desktop application, showing a live preview of the camera module. That it is not possible using shell. With the shell is posible to have a preview of the camera but in an individual window.
If you know how to do it with a shell command I will appreciate if you tell me how.

[quote=271654:@Mariano Poli]Gavin, I beleive that you didn’t understand my need.
I need to have a canvas control like, in a window of a desktop application, showing a live preview of the camera module. That it is not possible using shell. With the shell is posible to have a preview of the camera but in an individual window.
If you know how to do it with a shell command I will appreciate if you tell me how.[/quote]

The shell outputs images load them in the canvas. It’s easy as loading a picture.

For camera module create a file like camera.py
Inside script…

from picamera import PiCamera from time import sleep camera.start_preview() sleep(5) camera.capture('/home/pi/MyPictures/image.jpg') camera.stop_preview()
then use the shell and get the picture.
Here some more infoslink

People, Thank to all for your answers, but please try to understand the need.
I have no problem at all to get a still image from the camera using the shell command and Phyton, save the image in a file and then show it in a canvas.
What I need is to show in a “Canvas like control” a VIDEO PREVIEW in real time the camera and from that preview, when I see an image I am interesting to capture have the option to take a still image and save it to a file. The main need is to show the VIDEO preview in a control inside a desktop application.
As I mentioned in previous messages there was an old class for Real Basic named REAL CAPTURE CANVAS, now free but with no support http://sonicamigos.com/realcapture/, that use some old Quicktime libraries, and where is possible to define a video source and that video is shown inside the control in real time.
I hope my need is now more clear and someone in the community could give me a help.

How about a canvas with a paint event that takes that picture and draws it to itself, while a timer is doing a new capture and then invalidating it regularly like you wrote? It seems to be unclear if the preview can be redirected. Did you try if this works fast enough?

EDIT: Oh sorry! I’ve just seen that Eugene’s new book about Pi programming with Xojo covers this topic.
It wouldn’t be fair to copy his code from the book, but that’s what he wrote:

The book comes with all the demo projects. Well invested money for Pi developers!

I need to see video at at least 25fps. So capturing an image and displaying it in a canvas will not cover my needs. I need to display in a “canvas like control” a video preview like doing video streaming.
I already bought the book and there was none solution to my needs there.
Thanks Ulrich, but I need something more complex.

Maybe here you can find something ( i didn’t do further research) to connect to the camera using twain drivers:
http://www.sane-project.org/sane-mfgs.html

cant use a html viewer & the pi web cam interface ?
maybe the V4L2 driver & it’s API’s via declares ?

Mariano, I did understand your question and I still believe it’s possible without much complication. I’d love to say that I’ll bust one of my Pis out and prove it but that’s unlikely as I’m behind on a few things. However, if you haven’t read the Pi camera docs, I urge you to do so. There are a number of possibilities here, if you think outside the box. At the bare minimum, you can ask your Xojo app to squirt the preview onto the screen at given coordinates - this solution wouldn’t put the video preview inside a Canvas BUT you could still take stills with a button in your Xojo app that, again, calls an extremely simple line of Python or two.

There are slicker ways to do this but there’s a bare minimum solution right there and a max of 5 minutes coding time.

[quote=271726:@Mariano Poli]People, Thank to all for your answers, but please try to understand the need.
I have no problem at all to get a still image from the camera using the shell command and Phyton, save the image in a file and then show it in a canvas.
What I need is to show in a “Canvas like control” a VIDEO PREVIEW in real time the camera and from that preview, when I see an image I am interesting to capture have the option to take a still image and save it to a file. The main need is to show the VIDEO preview in a control inside a desktop application.
As I mentioned in previous messages there was an old class for Real Basic named REAL CAPTURE CANVAS, now free but with no support http://sonicamigos.com/realcapture/, that use some old Quicktime libraries, and where is possible to define a video source and that video is shown inside the control in real time.
I hope my need is now more clear and someone in the community could give me a help.[/quote]

Raspivid shows video in .h264 format, xojo can’t do that just like that. Use the commands and load the images every 100ms. That’s the max movement you can get.
Or contact a plugin developer.

MBS Plugin 16.4pr1 includes the class for the camera.
Try it!

@Christian Schmitz
I am downloading the new upgrade of MBS Plugin. I hope you work covers my needs. I will tell you as soon as I explore it.
Thanks in advance.

Christian:
Control is what I needed. Nice job.
It will be for sale alone, included in the MBS Plugins bundle or both ?
Is there any chance to control brithness, change ISO, etc. as parameters of the RaspberryPiCameraMBS control ?
You are taking still photos at a configurable rate given by the timer.
Two questions about that:

  1. Which is the maximun frame rate I will have conditions to obtain with combination of buffer, image size, changing the timer value ?
  2. Is there any chance to capture video at a reasonable rate of frames per second ? in a video format ?
    Thanks a lot !!!