Headless Raspberry camera grabber

#1

Is it possible to use the Raspberry camera in a headless application?

I tried using ofxOMXCamera addon but it seems that is uses textures so it is not possible to have the application run with no window. It compiles fine but crash when starting the app.

Does anyone know a way to do this?

I also found RaspiCam library and wondering if someone has a working example to have it work with OF.

Thanks

#2

It should be doable as long as you have something like the Headless Ghost (https://www.headlessghost.com/) plugged into the Pi.

#3

@Meach, you can try to force hdmi output (without needing hdmi cable conected), editing the file config.txt, located at /boot/config.txt with this commands

hdmi_force_hotplug=1
hdmi_drive=2
#4

I have a screen plugged in my Raspberry when I develop so those solution do not work.

#5

So far the only solution that I found working is using RaspiCam library. I was actually very easy to install and use and works also with AppNoWindow.

I guess I will be using this for now.

#6

Right, I understood the question wrong, I thought you wanted the Pi to run headless and not the app specifically. Yes, currently I don’t think it’s possible to run a headless app which requires textures via OF.

There would be hacky ways of doing it, but if you have a working solution already, it’s better to stick to that :slight_smile:

#7

The RaspiCam library should be usable from within oF - the website you link to actually has an example usage of it:


/**
*/
#include <ctime>
#include <fstream>
#include <iostream>
#include <raspicam/raspicam.h>
using namespace std;
 
int main ( int argc,char **argv ) {
    raspicam::RaspiCam Camera; //Cmaera object
    //Open camera 
    cout<<"Opening Camera..."<<endl;
    if ( !Camera.open()) {cerr<<"Error opening camera"<<endl;return -1;}
    //wait a while until camera stabilizes
    cout<<"Sleeping for 3 secs"<<endl;
    sleep(3);
    //capture
    Camera.grab();
    //allocate memory
    unsigned char *data=new unsigned char[  Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB )];
    //extract the image in rgb format
    Camera.retrieve ( data,raspicam::RASPICAM_FORMAT_RGB );//get camera image
    //save
    std::ofstream outFile ( "raspicam_image.ppm",std::ios::binary );
    outFile<<"P6\n"<<Camera.getWidth() <<" "<<Camera.getHeight() <<" 255\n";
    outFile.write ( ( char* ) data, Camera.getImageTypeSize ( raspicam::RASPICAM_FORMAT_RGB ) );
    cout<<"Image saved at raspicam_image.ppm"<<endl;
    //free resrources    
    delete data;
    return 0;
}
1 Like