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

Categories

HOME
ios
ssis
dynamics-crm-365
auth0
jsonschema
svg.js
antlr
weblogic11g
vsix
go-gorm
struts2-jquery
drag
push
calayer
command-line-arguments
google-cloud-sdk
googletest
android-dialogfragment
round-robin
exe4j
game-maker-language
pydev
missingmethodexception
background-subtraction
pvs-studio
regex-group
point-cloud-library
masstransit
arduino-esp8266
opensuse
gcp
bluebird
matterjs
reed-solomon
groove
dashboard-designer
executorservice
argparse
xaf
ecmascript-4
knowledge-management
plasticscm
linear
textangular
gretl
mobile-browser
sql-mode
notimplementedexception
reactivex
itertools
catalina
glumpy
swift-package-manager
qtcpserver
plotrix
agile-processes
ispconfig
jasny-bootstrap
balsamiq
jstorm
schematiq
hl7-v2
metalkit
greenfoot
jedi
folder-structure
xsb
treegrid
mailx
genexus-gam
easynetq
window-server
janino
misra
laravel-validation
ituneslibrary
hebrew
tlb
array-address
blueprint
django-endless-pagination
couchrest
rte
zephir
mainwindow
loadlibrary
google-chrome-frame
python-dateutil
impdp
slimbox
timestamp-with-timezone
teamcity-7.0
jsr223
maven-bundle-plugin
undeclared-identifier
sticky-footer
adaboost
ms-access-97
gemstone
blackberry-os-v5
retain
plinqo
jboss-cache
cassandra-0.7
pinging
posterous
gedcom
xlink
usenet
metaphone

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App