summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_pt
diff options
context:
space:
mode:
Diffstat (limited to 'ftnoir_tracker_pt')
-rw-r--r--ftnoir_tracker_pt/ftnoir_tracker_pt.cpp2
-rw-r--r--ftnoir_tracker_pt/video_widget.cpp59
-rw-r--r--ftnoir_tracker_pt/video_widget.h4
3 files changed, 34 insertions, 31 deletions
diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
index 09e758c7..f18671e2 100644
--- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
+++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp
@@ -177,7 +177,7 @@ void Tracker::StartTracker(QFrame* videoframe)
videoframe->setLayout(layout);
video_widget->resize(VIDEO_FRAME_WIDTH, VIDEO_FRAME_HEIGHT);
videoframe->show();
- connect(&timer, SIGNAL(timeout()), this, SLOT(paint_widget()), Qt::QueuedConnection);
+ connect(&timer, SIGNAL(timeout()), this, SLOT(paint_widget()));
timer.start(40);
camera.start();
start();
diff --git a/ftnoir_tracker_pt/video_widget.cpp b/ftnoir_tracker_pt/video_widget.cpp
index 7ca1892a..e6d1e24c 100644
--- a/ftnoir_tracker_pt/video_widget.cpp
+++ b/ftnoir_tracker_pt/video_widget.cpp
@@ -12,39 +12,44 @@
using namespace cv;
using namespace std;
-void VideoWidget::update_image(Mat frame, std::auto_ptr< vector<Vec2f> > points)
+void VideoWidget::update_image(Mat frame, std::auto_ptr< vector<Vec2f> >)
{
QMutexLocker((QMutex*)&mtx);
- this->frame = frame;
- this->points = points;
-
- QImage qframe;
- // convert to QImage
- if (frame.channels() == 3)
- qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols * 3, QImage::Format_RGB888).rgbSwapped();
- else if (frame.channels() == 1)
- qframe = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.cols, QImage::Format_Indexed8).convertToFormat(QImage::Format_RGB888);
- if (qframe.size() == size() || (qframe.width() <= width() && qframe.height() <= height()))
+ if (frame.channels() != 3 && frame.channels() != 1)
+ return;
+
+ int width = frame.cols, height = frame.rows;
+ unsigned char* src = frame.data;
+
+ QImage qframe(width, height, QImage::Format_RGB888);
+ if (frame.channels() == 3)
{
- ;;;
+ uchar* data = qframe.bits();
+ const int pitch = qframe.bytesPerLine();
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ const int pos = 3 * (y*width + x);
+ data[y * pitch + x * 3 + 0] = src[pos + 2];
+ data[y * pitch + x * 3 + 1] = src[pos + 1];
+ data[y * pitch + x * 3 + 2] = src[pos + 0];
+ }
+ } else {
+ uchar* data = qframe.bits();
+ const int pitch = qframe.bytesPerLine();
+ for (int y = 0; y < height; y++)
+ for (int x = 0; x < width; x++)
+ {
+ const int pos = (y*width + x);
+ data[y * pitch + x * 3 + 0] = src[pos];
+ data[y * pitch + x * 3 + 1] = src[pos];
+ data[y * pitch + x * 3 + 2] = src[pos];
+ }
+ }
+ if (qframe.size() == size() || (qframe.width() <= this->width() && qframe.height() <= this->height())) {
}
else
qframe = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
- QPainter painter(&qframe);
- painter.setPen(Qt::red);
- painter.setBrush(Qt::red);
- if (points.get() != NULL) {
- const int crosshair_radius = 10;
- for (vector<Vec2f>::iterator iter = points->begin();
- iter != points->end();
- ++iter)
- {
- int x = (*iter)[0];
- int y = (*iter)[1];
- painter.drawLine(QLine(x-crosshair_radius, y, x+crosshair_radius, y));
- painter.drawLine(QLine(x, y-crosshair_radius, x, y+crosshair_radius));
- }
- }
pixmap = QPixmap::fromImage(qframe);
}
diff --git a/ftnoir_tracker_pt/video_widget.h b/ftnoir_tracker_pt/video_widget.h
index eb63a15e..57be8bff 100644
--- a/ftnoir_tracker_pt/video_widget.h
+++ b/ftnoir_tracker_pt/video_widget.h
@@ -26,7 +26,7 @@ class VideoWidget : public QWidget
public:
VideoWidget(QWidget *parent) : QWidget(parent), mtx() {
}
- void update_image(cv::Mat frame, std::auto_ptr< std::vector<cv::Vec2f> > points);
+ void update_image(cv::Mat frame, std::auto_ptr< std::vector<cv::Vec2f> >);
protected slots:
void paintEvent( QPaintEvent* e ) {
QMutexLocker((QMutex*)&mtx);
@@ -35,9 +35,7 @@ protected slots:
}
private:
- cv::Mat frame;
QMutex mtx;
- std::auto_ptr< std::vector<cv::Vec2f> > points;
QPixmap pixmap;
};