haraldhv
/
aigo
Archived
1
0
Fork 0

Added static camera

This commit is contained in:
Harald Hvaal 2007-03-14 17:02:22 +00:00
parent 2c66c10eed
commit 7fedbe263e
7 changed files with 64 additions and 31 deletions

View File

@ -3,6 +3,7 @@ project(aigolib)
set(AIGO_SRCS set(AIGO_SRCS
camera.cpp camera.cpp
quickcam.cpp quickcam.cpp
staticcam.cpp
settings.cpp settings.cpp
state.cpp state.cpp
image.cpp image.cpp

View File

@ -9,6 +9,17 @@ Camera::Camera(int width, int height)
pixels = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, DEPTH, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); pixels = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, DEPTH, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
} }
Camera::Camera( void )
: pixels(0)
{
//does not initialize anything
}
void Camera::init(int width, int height)
{
pixels = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, DEPTH, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
}
Camera::~Camera( void ) Camera::~Camera( void )
{ {
SDL_FreeSurface(pixels); SDL_FreeSurface(pixels);

View File

@ -12,7 +12,9 @@ class Camera
SDL_Surface* getSurface ( void ) { return pixels; } SDL_Surface* getSurface ( void ) { return pixels; }
protected: protected:
Camera( void );
SDL_Surface *pixels; SDL_Surface *pixels;
void init(int width, int height);
}; };

19
lib/staticcam.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "staticcam.h"
StaticCam::StaticCam(char *filename)
: Camera()
{
loaded = SDL_LoadBMP(filename);
init(loaded->w, loaded->h);
SDL_CreateRGBSurface(SDL_SWSURFACE, loaded->w, loaded->h, 8, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
}
StaticCam::~StaticCam( void )
{
SDL_FreeSurface(loaded);
}
void StaticCam::update( void )
{
SDL_BlitSurface(loaded, 0, pixels, 0);
}

23
lib/staticcam.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _STATICCAM_H_
#define _STATICCAM_H_
#include "camera.h"
class StaticCam : public Camera
{
public:
StaticCam( char *filename );
virtual ~StaticCam( void );
void update( void );
private:
SDL_Surface *loaded;
};
#endif /* ifndef _QUICKCAM_H_ */

View File

@ -3,53 +3,29 @@
#include <state.h> #include <state.h>
#include "image.h" #include "image.h"
#define USESTATICIMAGE
SDL_Surface *getSurface( void )
{
static SDL_Surface *newSurface = NULL;
if (newSurface == NULL)
{
qDebug() << "Now loading bmp...";
SDL_Surface *surface = SDL_LoadBMP("data/bilde.bmp");
newSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h,
8, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_BlitSurface(surface, 0, newSurface, 0);
delete surface;
}
return newSurface;
}
AigoQt::AigoQt(QWidget *parent) AigoQt::AigoQt(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
setupUi(this); setupUi(this);
#ifndef USESTATICIMAGE cam = new StaticCam("data/bilde.bmp");
cam = new Quickcam("/dev/video0");
#endif
timer = new QTimer(this); timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked())); connect(timer, SIGNAL(timeout()), this, SLOT(on_buttonDrawPoints_clicked()));
timer->start(10); timer->start(10);
copy = Image::copySurface(getSurface()); copy = Image::copySurface(cam->getSurface());
} }
AigoQt::~AigoQt( void ) AigoQt::~AigoQt( void )
{ {
#ifndef USESTATICIMAGE
delete cam; delete cam;
#endif
} }
void AigoQt::updateImage( void ) void AigoQt::updateImage( void )
{ {
#ifndef USESTATICIMAGE
cam->update(); cam->update();
#endif SDL_Surface *s = cam->getSurface();
SDL_Surface *s = getSurface();
if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value()); if (checkThreshold->isChecked()) Image::threshold(s, blackImageThreshold->value(), whiteImageThreshold->value());
SDL_BlitSurface(s, NULL, copy, NULL); SDL_BlitSurface(s, NULL, copy, NULL);
@ -75,7 +51,7 @@ void AigoQt::on_buttonSetCorners_clicked( void )
void AigoQt::on_buttonGenerateState_clicked( void ) void AigoQt::on_buttonGenerateState_clicked( void )
{ {
State state = State::generateState(getSurface(), settings); State state = State::generateState(cam->getSurface(), settings);
state.printState(); state.printState();
} }
@ -99,10 +75,10 @@ void AigoQt::on_buttonDrawPoints_clicked( void )
for (int j = 0; j < 19; j++) for (int j = 0; j < 19; j++)
{ {
point p = State::positionPoint(i, j, settings); point p = State::positionPoint(i, j, settings);
((uint32_t*)getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000; ((uint32_t*)cam->getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000;
} }
} }
SDL_Surface *s = getSurface(); SDL_Surface *s = cam->getSurface();
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)));
} }

View File

@ -4,6 +4,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <ui_main.h> #include <ui_main.h>
#include <quickcam.h> #include <quickcam.h>
#include <staticcam.h>
#include <QTimer> #include <QTimer>
#include <settings.h> #include <settings.h>
@ -29,7 +30,7 @@ class AigoQt : public QMainWindow, public Ui::AigoQt
void updateImage(); void updateImage();
private: private:
Quickcam *cam; StaticCam *cam;
QTimer *timer; QTimer *timer;
Settings settings; Settings settings;