diff options
-rw-r--r-- | ftnoir_tracker_aruco/ar_video_widget.cpp | 24 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/ar_video_widget.h | 8 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 6 |
3 files changed, 18 insertions, 20 deletions
diff --git a/ftnoir_tracker_aruco/ar_video_widget.cpp b/ftnoir_tracker_aruco/ar_video_widget.cpp index b727679b..149a19ee 100644 --- a/ftnoir_tracker_aruco/ar_video_widget.cpp +++ b/ftnoir_tracker_aruco/ar_video_widget.cpp @@ -11,31 +11,29 @@ using namespace std; -void ArucoVideoWidget::update_image(unsigned char *frame, int width, int height) +void ArucoVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); - memcpy(fb, frame, width * height * 3); - this->width = width; - this->height = height; + _frame = frame; } void ArucoVideoWidget::update_and_repaint() { QMutexLocker foo(&mtx); - if (width*height <= 0) + if (_frame.cols*_frame.rows <= 0) return; - QImage qframe = QImage(width, height, QImage::Format_RGB888); + QImage qframe = QImage(_frame.cols, _frame.rows, QImage::Format_RGB888); uchar* data = qframe.bits(); const int pitch = qframe.bytesPerLine(); - for (int y = 0; y < height; y++) + for (int y = 0; y < _frame.rows; y++) { - const int part = y*width; - for (int x = 0; x < width; x++) + for (int x = 0; x < _frame.cols; x++) { - const int pos = 3 * (part + x); - data[y * pitch + x * 3 + 0] = fb[pos + 2]; - data[y * pitch + x * 3 + 1] = fb[pos + 1]; - data[y * pitch + x * 3 + 2] = fb[pos + 0]; + const auto& elt = _frame.at<cv::Vec3b>(y, x); + const CvScalar elt2 = elt; + data[y * pitch + x * 3 + 0] = elt2.val[2]; + data[y * pitch + x * 3 + 1] = elt2.val[1]; + data[y * pitch + x * 3 + 2] = elt2.val[0]; } } auto qframe2 = qframe.scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation); diff --git a/ftnoir_tracker_aruco/ar_video_widget.h b/ftnoir_tracker_aruco/ar_video_widget.h index e1c7cff8..b95d1873 100644 --- a/ftnoir_tracker_aruco/ar_video_widget.h +++ b/ftnoir_tracker_aruco/ar_video_widget.h @@ -16,6 +16,7 @@ #include <QPainter> #include <QPaintEvent> #include <QTimer> +#include <opencv/cv.hpp> // ---------------------------------------------------------------------------- class ArucoVideoWidget : public QWidget @@ -23,11 +24,11 @@ class ArucoVideoWidget : public QWidget Q_OBJECT public: - ArucoVideoWidget(QWidget *parent) : QWidget(parent), fb(), width(0), height(0) { + ArucoVideoWidget(QWidget *parent) : QWidget(parent) { connect(&timer, SIGNAL(timeout()), this, SLOT(update_and_repaint())); timer.start(60); } - void update_image(unsigned char* frame, int width, int height); + void update_image(const cv::Mat& frame); protected slots: void paintEvent( QPaintEvent* e ) { QMutexLocker foo(&mtx); @@ -40,8 +41,7 @@ private: QMutex mtx; QPixmap pixmap; QTimer timer; - char fb[2048*2048*3]; - int width,height; + cv::Mat _frame; }; #endif // VIDEOWIDGET_H diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index a918d020..e063be62 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -280,12 +280,12 @@ start: char buf[128]; + frame = color.clone(); + ::sprintf(buf, "Hz: %d", last_fps); cv::putText(frame, buf, cv::Point(10, 32), cv::FONT_HERSHEY_PLAIN, scale, cv::Scalar(0, 255, 0), scale); ::sprintf(buf, "Jiffies: %ld", (long) (10000 * (time - tm) / freq)); cv::putText(frame, buf, cv::Point(10, 54), cv::FONT_HERSHEY_PLAIN, scale, cv::Scalar(80, 255, 0), scale); - - frame = color; if (markers.size() == 1 && markers[0].size() == 4) { const aruco::Marker& m = markers.at(0); @@ -362,7 +362,7 @@ start: } if (frame.rows > 0) - videoWidget->update_image(frame.data, frame.cols, frame.rows); + videoWidget->update_image(frame); } } |