Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static IplImage* qImage2IplImage(const QImage& qImage)
- {
- int width = qImage.width();
- int height = qImage.height();
- // Creates a iplImage with 3 channels
- IplImage *img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
- char * imgBuffer = img->imageData;
- //Remove alpha channel
- int jump = (qImage.hasAlphaChannel()) ? 4 : 3;
- for (int y=0;y<img->height;y++){
- QByteArray a((const char*)qImage.scanLine(y), qImage.bytesPerLine());
- for (int i=0; i<a.size(); i+=jump){
- //Swap from RGB to BGR
- imgBuffer[2] = a[i];
- imgBuffer[1] = a[i+1];
- imgBuffer[0] = a[i+2];
- imgBuffer+=3;
- }
- }
- return img;
- }
Advertisement
Add Comment
Please, Sign In to add comment