### opencv

#### View results of affine transform

I am trying to find out the reason why when I apply affine transformations on an image in OpenCV, the result of it is not visible in the preview window, but the entire window is black.How can I find workaround for this problem so that I can always view my transformed image (the result of the affine transform) in the window no matter the applied transformation? Update: I think that this happens because all the transformations are calculated with respect to the origin of the coordinate system (top left corner of the image). While for rotation I can specify the center of the rotation, and I am able to view the result, when I perform scaling I am not able to control where the transformed image goes. Is it possible to somehow move the coordinate system to make the image fit in the window? Update2: I have an image which contains only ROI at some position in it (the rest of the image is black), and I need to apply a set of affine transforms on it. To make things simpler and to see the effect of each individual transform, I applied each transform one by one. What I noticed is that, whenever I move (translate) the image such that the center of the ROI is in the center of the coordinate system (top left corner of the view window), all the affine transforms perform correctly without moving. However, by translating the center of ROI at the center of the coordinate system, the upper and the left part of the ROI remain cut out of the current view window. If I move ROI's central point to another point in the view window (for example the window center), an affine transform of type: A=[a 0 0; 0 b 0] (A is 2x3 matrix, parameter of the warpAffine function) moves the image (ROI), outside of the view window (which doesn't happen if the ROI's center is in the top-left corner). How can I modify the affine transform so the image doesn't move out of its place (behaves the same way as when the ROI center is in the center of the coordinate system)?

If you want to be able to apply any affine transform, you will not always be able to view it. A better idea might be to manually apply your transform to 4 corners of a square and then look at the coordinates where those 4 points end up. That will tell you where your image is going. If you have several transforms, just combine them into one transform. If you have 3 transforms [A],[B],[C] transforming an image by A,then B, then C is equivalent to transforming the image once by [C]*[B]*[A] If your transforms are in 2x3 matrices, just convert them to 3x3 matrices by adding [0,0,1] as the new bottom row, then multiply the 3x3 matrices together, when you are finished the bottom row will be unchanged, then just drop it to get your new, combined affine transform Update If you want to apply a transform to an object as if the object were somewhere else. You can combine 3 transforms. First translate the object to the location you want it to be transformed in (center of coordinate system in your case) with an affine transform [A]. Then apply your scaling transform [B], then a translation back to where you started. The translation back should be the inverse of [A]. That means your final transform would be final_transform = [A].inv()*[B]*[A] order of operations reads right to left when doing matrix multiplication.

### Related Links

Fisheye and Pinhole pixel correlation

Tracking two hands with OpenCV

Meaning of Maximum Line Gap in HoughTransform

How to extract the area of the text in a frame?

Compute transformation between points given in two coordinate frames

Saving SVM detector in float values

How can I speed up or replace code to combine close contours?

The exact build configuration of pre-built OpenCV 3.1 on Windows

What is the shape/order of points expected by CV2 plotChessboardCorners and cornersSubPix?

find objects with bounding boxes

SolvePnP giving OpenCV Error: Assertion failed

Get darker lines of an image using opencv

Image segmentation code examples working with hair?

Can't detect shapes from the webcam

Cmake error while configuring openCV with CUDA

Opencv doesn't show anything from video camera or doesn't read camera data