I already said this - read your RGB data and put it into a QImage with setPixel() ... what else do you need??
I already said this - read your RGB data and put it into a QImage with setPixel() ... what else do you need??
Don't use setPixel. It's very slow. Have a look here for some hints on how to do it: http://www.qtcentre.org/forum/f-qt-p...ghlight=ffmpeg
and this might be use useful (example code using OpenCV to capture from webcams)
http://www.qtcentre.org/forum/f-qt-p...ghlight=ffmpeg
If you want to roll your own, you could use the following code:
This won't be painfully slow like using setPixel(), but it will never be as fast as using optimized libraries like OpenCV either.Qt Code:
int w=..., h=...; uchar* input=...; for (int y=0;y<h;y++) { QRgb* line = img.scanLine(y); for (int x=0;x<w;x++) *(line++) = qRgb(input[y*w + 3*x], input[y*w + 3*x+1], input[y*w + 3*x+2]); }To copy to clipboard, switch view to plain text mode
Thanks for your advice, but i would like to show my code so that u get my problem:
here is the code which captures image from the webcam:
when video format is VIDEO_PALETTE_RGB32 the display code displays good quality image.Qt Code:
static struct video_mmap vm; mmap_test(int i) { vm.format = VIDEO_PALETTE_RGB32; vm.frame = 0; vm.width = 176; vm.height = 144; ioctl(device_fd, VIDIOCMCAPTURE, &vm); ioctl(device_fd, VIDIOCSYNC, &numframe); return buffer; }To copy to clipboard, switch view to plain text mode
here is the display code:
Qt Code:
display() { raw_buf = mmap_test(0); //this gets the Image buffer memcpy(img->bits(), raw_buf, 101376); //101376 is width*height*32 bits is 4 chars 176*144*4 paint.drawImage(0, 0, *img, 0, 0, -1, -1); }To copy to clipboard, switch view to plain text mode
but when i change format = VIDEO_PALETTE_RGB24 i get a carbon kind of image.I want to know is there a problem in the capture or the QImage does not support VIDEO_PALETTE_RGB24 format.If it doesnt is there any other alternate way to do this.
Last edited by jpn; 28th May 2008 at 16:37. Reason: missing [code] tags
We just explained how to do exactly that. Choose a method that you like.
You can't copy directly because the image formats are different. QImage expects 32bit format. If you're copying from 24bit source then you need to use one of the methods that was posted.
Thanks for your advice and i have done exactly what has been mentioned by copying individual pixels.Here is the code:
Qt Code:
for (int y=0;y<h;y++) { QRgb* line = (QRgb*)img.scanLine(y); for (int x=0;x<w;x++) *(line++) = qRgb(input[y*w + 3*x], input[y*w + 3*x+1], input[y*w + 3*x+2]); } status = pix.convertFromImage(img, Qt::ColorOnly); paint.drawPixmap(0, 0, pix, 0, 0, -1, -1);To copy to clipboard, switch view to plain text mode
Now am i displaying the image correctly???After copying the individual pixels into the image,first i convert it into pixmap and than draw it using QPainter.
Last edited by jpn; 30th May 2008 at 17:03. Reason: missing [code] tags
Last edited by spud; 30th May 2008 at 14:08. Reason: spelling error
Looks about right to me. You can use drawImage directly so you dont have to convert (although the conversion happens implicitly anyway).
You might have a problem with "endianess" (big endian (MSB first) or little endian (LSB first)), RGB vs BGR or similar problem.
Make sure you know exactly which format your image is, and then adjust the above suggested code.
Have a look at image formats here:
http://doc.trolltech.com/4.3/qimage.html#image-formats
I am using Qt 3.3 version and to have an endian problem the image data which i get is an unsigned char and i copy the image also as an unsigned char itself.
Bookmarks