CatherineH
Posts: 7
Joined: Sat Sep 21, 2013 1:35 am

Raspberry pi Camera not reading any bytes

Tue Feb 18, 2014 8:44 pm

I am attempting to use Chris Cumming's Raspberry Pi Camera API.

http://robotblogging.blogspot.ca/2013/1 ... i-for.html

The sample code compiles, and seems to work as expected. Attempting to write a very basic frame grab seems to result in no bytes being read however. Here's my sample code:

Code: Select all

#include <stdio.h>
#include <unistd.h>
#include "camera.h"
#include "graphics.h"

#define MAIN_TEXTURE_WIDTH 512
#define MAIN_TEXTURE_HEIGHT 512

char tmpbuff[MAIN_TEXTURE_WIDTH*MAIN_TEXTURE_HEIGHT*4];

int main(int argc, const char **argv)
{
	CCamera* cam = StartCamera(MAIN_TEXTURE_WIDTH, MAIN_TEXTURE_HEIGHT,30,1,true);
	int val = cam->ReadFrame(0,tmpbuff,sizeof(tmpbuff));
	printf("Bytes read: %d\n",val);

}
This returns:

Code: Select all

[email protected] ~/picamerademo $ ./picamdemo
Init camera output with 512/512
Creating pool with 3 buffers of size 1048576
Camera successfully created
Bytes read: 0
So... I'm confused as to why no bytes were read, yet no error was reported. I'm wondering if I'm supposed to do something else between StartCamera() and ReadFrame().

CatherineH
Posts: 7
Joined: Sat Sep 21, 2013 1:35 am

Re: Raspberry pi Camera not reading any bytes

Tue Feb 18, 2014 9:59 pm

Okay, so it turns out that if I add a call to the function BeginFrame(), it can get data locally, but it also takes over the screen, which I don't want. I'm looking into some of the other header files to see why it gets info in this call, or how to disable showing it to the screen.

CatherineH
Posts: 7
Joined: Sat Sep 21, 2013 1:35 am

Re: Raspberry pi Camera not reading any bytes

Tue Feb 18, 2014 10:10 pm

Okay, so I think I now have my code doing what I need.

As they are defined, BeginFrame() and EndFrame() are as follows:

Code: Select all

void BeginFrame()
{
	// Prepare viewport
	glViewport ( 0, 0, GScreenWidth, GScreenHeight );
	check();

	// Clear the background
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	check();
}

Code: Select all

void EndFrame()
{
	eglSwapBuffers(GDisplay,GSurface);
	check();
}
So if I only call EndFrame() without calling BeginFrame(), it copies the camera data into a buffer without pushing into the screen.

There's probably a better way of doing this though.

wibble82
Posts: 66
Joined: Sun Jan 27, 2013 5:06 pm
Contact: Website

Re: Raspberry pi Camera not reading any bytes

Tue Apr 15, 2014 7:45 pm

HI Catherine

The library uses opengl to do a lot of work, which is why you need to do a begin and end frame. Most opengl commands really just queue up instructions for the gpu, which get submitted when swap buffers is called. I beleive you might be able to use an opengl flush command instead to make them all happen without taking over the screen though.

Off the top of my head I can't think of simple instructions on how to use opengl without affecting the screen at all I'm afraid, although obviously you can insert all your own rendering within that begin/end frame.

-Chris

Return to “C/C++”