Added image library and threshold function. Moved pixel access defines from state to image class.
This commit is contained in:
parent
2b39f792a1
commit
7d7e61fe28
|
@ -5,6 +5,7 @@ set(AIGO_SRCS
|
||||||
quickcam.cpp
|
quickcam.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
state.cpp
|
state.cpp
|
||||||
|
image.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
#find SDL and its related libraries
|
#find SDL and its related libraries
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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_ */
|
12
lib/state.h
12
lib/state.h
|
@ -4,17 +4,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "image.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++)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "aigoqt.h"
|
#include "aigoqt.h"
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <state.h>
|
#include <state.h>
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
AigoQt::AigoQt(QWidget *parent)
|
AigoQt::AigoQt(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -9,8 +10,8 @@ AigoQt::AigoQt(QWidget *parent)
|
||||||
cam = new Quickcam("/dev/video0");
|
cam = new Quickcam("/dev/video0");
|
||||||
|
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
|
connect(timer, SIGNAL(timeout()), this, SLOT(updateImage()));
|
||||||
timer->start(200);
|
timer->start(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ void AigoQt::updateImage( void )
|
||||||
{
|
{
|
||||||
cam->update();
|
cam->update();
|
||||||
SDL_Surface *s = cam->getSurface();
|
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)));
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
||||||
on_buttonGenerateState_clicked();
|
on_buttonGenerateState_clicked();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue