C++ OpenCV Video Processing with Qt: Real-Time Image Manipulation
#include "video_processing.h" #include <opencv2/dnn.hpp> #include <opencv2/opencv.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/highgui.hpp>
VideoProcessor::VideoProcessor(QObject *parent) : QObject(parent) { m_camera = new QCamera(this); m_imageCapture = new QCameraImageCapture(m_camera, this);
connect(m_imageCapture, SIGNAL(imageAvailable(int,QVideoFrame)), this, SLOT(processFrame(int,QVideoFrame)));
m_camera->setCaptureMode(QCamera::CaptureStillImage);
m_camera->start();
}
VideoProcessor::~VideoProcessor(){}
void VideoProcessor::startCamera() { m_imageCapture->capture(); }
void VideoProcessor::processFrame(int requestid, const QVideoFrame &frame) { Q_UNUSED(requestid);
// Convert QVideoFrame to cv::Mat
cv::Mat img;
cv::cvtColor(frame.image(), img, cv::COLOR_BGR2RGB);
// Process the image using OpenCV functions
// ...
// Convert the processed image back to QImage
QImage processedImg(img.data, img.cols, img.rows, QImage::Format_RGB888);
// Emit signal with the processed image
emit frameProcessed(processedImg);
}
原文地址: https://www.cveoy.top/t/topic/pPJV 著作权归作者所有。请勿转载和采集!