Hi,
I have written a small program which reads an image from an usb camera and converts it to the hsv-colorspace.
But the Beagle computes only 37 frames per second (99% cpu load). Is this speed normal for the beagleboard? I thought the beagle could be
much faster. The image is only 160x120 pixels.
Here is my program:
/#include <iostream>
#include <cmath>
#include <ctime>
#include "Webcam.h"
#include <unistd.h>
#include <sys/time.h>
using namespace std;
Webcam * cam = new Webcam("/dev/video0", 160, 120);
unsigned char * converted = (unsigned char *) malloc(640*480*3);
int cy=0;
struct timeval time;
int timeold=0;
uint8_t max=0;
uint8_t min=255;
uint8_t delta=0;
uint16_t val;
uint16_t hue;
uint16_t sat;
uint8_t x1;
uint8_t x2;
uint8_t x3;
while(true){
unsigned char * raw = cam->getImagePointer();
//RGB to HSV conversion
for(unsigned int x=0; x<(160*120*3)-3; x+=3){
bool cont=true;
x1 = raw[x];
x2 = raw[x+1];
x3 = raw[x+2];
max = fmax(x1, fmax(x2, x3));
min = fmin(x1, fmin(x2, x3));
delta = max - min;
//cout << "min/max ok" << endl;
//hsv.val
val=max;
if(val==0){
converted[x]=0;
converted[x+1]=0;
converted[x+2]=max;
//return hsv;
cont=false;;
}
//hsv.sat
if(cont==true){
sat = 255 * delta / val;
if(sat==0){
converted[x]=0;
converted[x+1]=0;
converted[x+2]=max;
//return hsv;
cont=false;;
}
}
//cout << "val/sat ok" << endl;
if(cont==true){
if(delta>0){
if(max==x1){ converted[x] = (uint8_t)(0 + 43 * (x2 -
x3) / delta);
}
else if(max==x2){
converted[x] = (uint8_t)(85 + 43 * (x2 -
x1) / delta);
}
else{ //max = rgb.blue
converted[x] = (uint8_t)(171 + 43 * (x1 -
x2) / delta);
} }
else{
converted[x] = 0;
}
//cout << "hue ok" << endl;
converted[x+2] = val;
}
}
gettimeofday(&time, NULL);
if(time.tv_sec > timeold+1){
cout << "CPS: " << cy/2.0 << endl;
timeold=time.tv_sec;
cy=0;
}
cy++;
}
cam->stopRead();
free(converted);
}/
Regards, Joern