Question

I work on Win7 x64, with openCV and Visual Studio 2010, programming in c++. I want copying an image (call it image) to a rectangular area of another image (call it RR_image). This area, however, is rotated.

here is image:

enter image description here

and here is RR_image: enter image description here (as you see, I've already rotated first image)

I would copy first image in red rectangle.

How many and what ways are there to do this?

I know about ROI and: img1.copyTo(img2.rowRange(...), img2.colRange(...));

Thanks!

Était-ce utile?

La solution

The main problem is that OpenCV doesn't support transparency in images, which is what you need to accomplish that task in an easy way.

So, one way to do it is to write a custom function/method to iterate over the rotated (source) image copying the pixels to the destination image, while ignoring the background pixels (a specific shade of gray, for instance). This approach is very limited, though.

EDIT:

OpenGL can certainly do the job, but it brings a complexity that you probably don't want on your hands right know. Fortunately there are other alternatives like ImakeMagick, which provides a C++ API through ImageMagick++ and it can certainly handle transparent images. Take a look at A Gentle Introduction to Magick++.

The QImage class from Qt can probably do this as well.

Autres conseils

I solved my problem with Qt library and OpenCV.

Here how:

Given image and RR_image in order to copy the former into the latter, I used this code:

QPainter painter(&RR_image);
painter.drawImage( (float)p1.x(),(float)p2.y(), image);

RR_image and image must be a QImage object, so I have to covert them from Mat to QImage with this code:

cvtColor(image, image,CV_BGR2RGB);
QImage image= QImage((uchar*) image.data, image.cols, image.rows, image.step, QImage::Format_RGB888);

The result is: enter image description here

Hope this will help someone!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top