I know this thread is quite old, but still it is a very good wrapper to get images from webcam or whatnot.
If for some reason you dont need some fancy 32 bit format you could change the updatePixmap function to only use one memcpy like this:
t.start();
//qDebug() << "Copying data";
bool start = false;
// check if the frame dimensions have changed
if(frame->width != imageWidth || frame->height != imageHeight) {
if(imageData) {
delete[] imageData;
}
start = true;
imageWidth = frame->width;
imageHeight = frame->height;
emit(frameSizeChanged(imageWidth, imageHeight));
imageData = new unsigned char[3*imageWidth*imageHeight];
}
int pixels = imageWidth * imageHeight;
uchar* src = (uchar*)(frame->imageData);
memcpy(imageData, src, pixels*3);
if(!start) {
++frames;
time += t.elapsed();
}
QTime t;
t.start();
//qDebug() << "Copying data";
bool start = false;
// check if the frame dimensions have changed
if(frame->width != imageWidth || frame->height != imageHeight) {
if(imageData) {
delete[] imageData;
}
start = true;
imageWidth = frame->width;
imageHeight = frame->height;
emit(frameSizeChanged(imageWidth, imageHeight));
imageData = new unsigned char[3*imageWidth*imageHeight];
}
int pixels = imageWidth * imageHeight;
uchar* src = (uchar*)(frame->imageData);
memcpy(imageData, src, pixels*3);
if(!start) {
++frames;
time += t.elapsed();
}
To copy to clipboard, switch view to plain text mode
Then you have to change the paintEvent method to create the tImg with RGB888 format like this:
QImage tImg
(imageData, imageWidth, imageHeight,
QImage::Format_RGB888);
QImage tImg(imageData, imageWidth, imageHeight, QImage::Format_RGB888);
To copy to clipboard, switch view to plain text mode
You might run into problem of RGB <--> BGR conversion, just modify the painter.drawImage call to
painter.
drawImage(QPoint(0,
0), tImg.
rgbSwapped());
painter.drawImage(QPoint(0,0), tImg.rgbSwapped());
To copy to clipboard, switch view to plain text mode
Bookmarks