haraldhv
/
aigo
Archived
1
0
Fork 0

Added image library and threshold function. Moved pixel access defines from state to image class.

This commit is contained in:
Harald Hvaal 2007-02-26 10:45:05 +00:00
parent 2b39f792a1
commit 7d7e61fe28
5 changed files with 53 additions and 13 deletions

View File

@ -5,6 +5,7 @@ set(AIGO_SRCS
quickcam.cpp
settings.cpp
state.cpp
image.cpp
)
#find SDL and its related libraries

19
lib/image.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "image.h"
namespace Image
{
void threshold(SDL_Surface *image, int lowerBound, int upperBound)
{
int x, y;
for (int i = 0; i < image->w * image->h; ++i)
{
int gray = GRAY(((uint32_t*)image->pixels)[i]);
if (gray > lowerBound && gray < upperBound)
((uint32_t*)image->pixels)[i] = 0xffffffff;
else
((uint32_t*)image->pixels)[i] = 0xff000000;
//gray | (gray << 8) | (gray << 16);
}
}
}

28
lib/image.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef _IMAGE_H_
#define _IMAGE_H_
#include <SDL/SDL.h>
// get pixel/something in array p of size w*h
#define PX_(p, x, y, w, h) ((p)[(x)+(y)*(w)])
// get pixel in SDL_Surface i
#define PX(i,x,y) (PX_((uint32_t*)(i)->pixels, (x), (y), (i)->w, (i)->h))
// get color components of pixel value. should probably be done in a nicer way
#define PXR(px) ((px) & 0xff)
#define PXG(px) (((px) & 0xff00) >> 8)
#define PXB(px) (((px) & 0xff0000) >> 16)
//get the grayscale value of the pixel
#define GRAY(px) ((PXR(px) + PXG(px) + PXB(px)) / 3)
// iterate over SDL_Surface s with variables x, y
#define iter_pixels(s,x,y) for (x = 0; x < s->w; x++) for (y = 0; y < s->h; y++)
namespace Image
{
void threshold(SDL_Surface *image, int lowerBound, int upperBound);
}
#endif /* ifndef _IMAGE_H_ */

View File

@ -4,17 +4,7 @@
#include "settings.h"
#include <SDL/SDL.h>
#include <stdint.h>
// get pixel/something in array p of size w*h
#define PX_(p, x, y, w, h) ((p)[(x)+(y)*(w)])
// get pixel in SDL_Surface i
#define PX(i,x,y) (PX_((uint32_t*)(i)->pixels, (x), (y), (i)->w, (i)->h))
// get color components of pixel value. should probably be done in a nicer way
#define PXR(px) ((px) & 0xff)
#define PXG(px) (((px) & 0xff00) >> 8)
#define PXB(px) (((px) & 0xff0000) >> 16)
// iterate over SDL_Surface s with variables x, y
#define iter_pixels(s,x,y) for (x = 0; x < s->w; x++) for (y = 0; y < s->h; y++)
#include "image.h"
/**

View File

@ -1,6 +1,7 @@
#include "aigoqt.h"
#include <QtDebug>
#include <state.h>
#include "image.h"
AigoQt::AigoQt(QWidget *parent)
: QMainWindow(parent)
@ -9,8 +10,8 @@ AigoQt::AigoQt(QWidget *parent)
cam = new Quickcam("/dev/video0");
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
timer->start(200);
connect(timer, SIGNAL(timeout()), this, SLOT(updateImage()));
timer->start(10);
}
@ -23,6 +24,7 @@ void AigoQt::updateImage( void )
{
cam->update();
SDL_Surface *s = cam->getSurface();
Image::threshold(s, sliderBlack->value(), sliderWhite->value());
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
on_buttonGenerateState_clicked();
}