Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MainWindow : public QWidget
- {
- Q_OBJECT
- public:
- MainWindow(MainController * controller, StructureSensor * camera, CvCapture *openCVCam, QWidget * parent = nullptr);
- //.........
- private:
- //.........
- };
- #endif // MAINWINDOW_H
- MainWindow::MainWindow(MainController * controller, StructureSensor * camera, CvCapture *openCVCam, QWidget * parent)
- {
- mUi.setupUi(this);
- mController = controller;
- mCamera = camera;
- mCvCapture=CvCapture;
- //.........
- }
- class RGBCamera : public QWidget {
- private:
- QLabel *imagelabel;
- QVBoxLayout *layout;
- QImage image;
- public:
- RGBCamera(QWidget *parent = 0);
- ~RGBCamera(void);
- void putImage(IplImage *);
- };
- #endif
- #include "RGBCamera.h"
- // Constructor
- RGBCamera::RGBCamera(QWidget *parent) : QWidget(parent) {
- layout = new QVBoxLayout;
- imagelabel = new QLabel;
- QImage dummy(100,100,QImage::Format_RGB32);
- image = dummy;
- layout->addWidget(imagelabel);
- for (int x = 0; x < 100; x ++) {
- for (int y =0; y < 100; y++) {
- image.setPixel(x,y,qRgb(x, y, y));
- }
- }
- imagelabel->setPixmap(QPixmap::fromImage(image));
- setLayout(layout);
- }
- RGBCamera::~RGBCamera(void) {
- }
- void RGBCamera::putImage(IplImage *cvimage) {
- int cvIndex, cvLineStart;
- // switch between bit depths
- switch (cvimage->depth) {
- case IPL_DEPTH_8U:
- switch (cvimage->nChannels) {
- case 3:
- if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) {
- QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32);
- image = temp;
- }
- cvIndex = 0; cvLineStart = 0;
- for (int y = 0; y < cvimage->height; y++) {
- unsigned char red,green,blue;
- cvIndex = cvLineStart;
- for (int x = 0; x < cvimage->width; x++) {
- // DO it
- red = cvimage->imageData[cvIndex+2];
- green = cvimage->imageData[cvIndex+1];
- blue = cvimage->imageData[cvIndex+0];
- image.setPixel(x,y,qRgb(red, green, blue));
- cvIndex += 3;
- }
- cvLineStart += cvimage->widthStep;
- }
- break;
- default:
- printf("This number of channels is not supportedn");
- break;
- }
- break;
- default:
- printf("This type of IplImage is not implemented in RGBCameran");
- break;
- }
- imagelabel->setPixmap(QPixmap::fromImage(image));
- }
- class MainWindow : public QWidget
- {
- Q_OBJECT
- private:
- RGBCamera *rgbcam;
- CvCapture *openCVCamera;
- public:
- MainWindow(CvCapture *cam, QWidget *parent = 0);
- protected:
- void timerEvent(QTimerEvent*);
- };
- #endif /*MYCAMERAWINDOW_H_*/
- #include "MainWindow.h"
- MainWindow::MainWindow(CvCapture *openCVCam_, QWidget *parent) : QWidget(parent) {
- openCVCamera = openCVCam_;
- QVBoxLayout *layout = new QVBoxLayout;
- rgbcam = new RGBCamera(this);
- layout->addWidget(rgbcam);
- setLayout(layout);
- resize(500, 400);
- startTimer(100); // 0.1-second timer
- }
- void MainWindow::timerEvent(QTimerEvent*) {
- IplImage *image = cvQueryFrame(openCVCamera);
- rgbcam->putImage(image);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement