OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 31 Jul 2019 12:14:28 -0500Matlab's PolynomialTransformation2D in OpenCVhttp://answers.opencv.org/question/216419/matlabs-polynomialtransformation2d-in-opencv/ Hello,
in Matlab there is a [PolynomialTransformation2D ](https://de.mathworks.com/help/images/ref/images.geotrans.polynomialtransformation2d.html) to transform curved images. I've looked for something similar in OpenCV but haven't found anything. Is there such a method to accomplish the same thing in OpenCV?AVK369Wed, 31 Jul 2019 12:14:28 -0500http://answers.opencv.org/question/216419/creating a rotation matrix in OpenCVhttp://answers.opencv.org/question/204092/creating-a-rotation-matrix-in-opencv/ I am trying to recreate a rotation matrix in OpenCV using one of the direction vectors along the z-axes but have not been having any success with it. I am also not sure if this can be done in a unique fashion but I was hoping to get some help from the forum.
So, initially, I try and create the rotation matrix that I want to recover. I do this as following:
import cv2
import numpy
def generate_fake_opencv_calibrations(num_calibs=10):
calibs = list()
cm = np.asarray([[300.0, 0.0, 400], [0, 300.0, 700.0], [0., 0., 1.]])
for i in range(num_calibs):
image_c = np.random.rand(6, 2) * 100.0
world_c = np.random.rand(6, 3)
_, r, t = cv2.solvePnP(world_c, image_c, cm, None, flags=cv2.SOLVEPNP_ITERATIVE)
# Create the rotation matrix
r, _ = cv2.Rodrigues(r)
calibs.append(r)
return calibs
So, the rotation matrix has all the properties that the rows and columns are orthonormal wrt to each other. So, what I was hoping to do is recreate this rotation matrix when I have the direction vector for the z-axes.
So, I have:
z = c[:, 2]
Now I wrote a function to create the other two axes as:
def create_orthonormal_basis(v):
v = v / np.linalg.norm(v)
if v[0] > 0.9:
b1 = np.asarray([0.0, 1.0, 0.0])
else:
b1 = np.asarray([1.0, 0.0, 0.0])
b1 -= v * np.dot(b1, v)
b1 *= np.reciprocal(np.linalg.norm(b1))
b2 = np.cross(v, b1)
return b1, b2, v
I can then create the matrix as:
x, y, z = create_orthonormal_basis(z)
mat = np.asarray([[x[0], y[0], z[0]],
[x[1], y[1], z[1]],
[x[2], y[2], z[2]]])
I was expecting this matrix to map a given point to approximately the same location, however this was not the case. So for a random case, I am getting the following:
For the input matrix, given by:
[-0.5917787 -0.69902414 0.40145141]
[ 0.76717701 -0.64127655 0.01427625]
[ 0.24746193 0.31643267 0.91576905]]
The output is:
[ 0.91588032 0. 0.40145141]
[-0.00625761 0.99987851 0.01427625]
[-0.40140263 -0.01558747 0.91576905]]
I take a random input like:
[0.33385406 0.91243684 0.33755828]
and map it using the original and reconstructed matrices and the output is quite different:
Original: [-0.69986985 -0.32418012 0.68046643]
Reconstructed: [0.44128362 0.91505592 0.16089295]
pamparanaMon, 26 Nov 2018 09:38:03 -0600http://answers.opencv.org/question/204092/Why is angle orientation inconsistent?http://answers.opencv.org/question/202171/why-is-angle-orientation-inconsistent/While working with 2D transformations and ellipses I painfully found out that the orientation of the angle in [ellipse](https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga28b2267d35786f5f890ca167236cbc69) and [getRotationMatrix2D](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gafbbc470ce83812914a70abfb604f4326) is different. **What is the reason for this inconsistency?**
The `ellipse` angle is positive in clockwise direction:![ellipse parameters](https://docs.opencv.org/master/ellipse.svg)
The `getRotationMatrix2D` angle orientation is [described](https://docs.opencv.org/master/da/d54/group__imgproc__transform.html#gafbbc470ce83812914a70abfb604f4326) as *Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).*
I assume that the coordinate system origin is in all OpenCV functions in the top-left corner, which is standard when working with images. smidmWed, 31 Oct 2018 05:17:13 -0500http://answers.opencv.org/question/202171/Geometric Library to transform OpenCV contours and polygonshttp://answers.opencv.org/question/192165/geometric-library-to-transform-opencv-contours-and-polygons/Do you guys use geometric libraries with OpenCV? And if so, what ones do you use? I need to use such a library to alter contours I have found through image processing. For example, parallel contours and scale polygons.
So I am looking for a c++ library that can perform geometric operations on polylines (that contain curves) and polygons. These geometric operations are mainly translate and scale.
Are you aware of any such libraries? I'm hoping the library can abstract away the mathematics as much as possible because I lack the math ability to do this myself - for eg do matrix and affine transformations.sazrWed, 23 May 2018 09:28:12 -0500http://answers.opencv.org/question/192165/How to compute the 3D location of a 2D point on the ground?http://answers.opencv.org/question/177170/how-to-compute-the-3d-location-of-a-2d-point-on-the-ground/I know the focal length f and the principal point of a camera P(x,y) and I can assume the ground plane is orthogonal to the image plane.
I have a 2D point on the picture that I know is on the ground, how do I get it on 3D using camera coordinates.
However I am not sure how to approach this? Any advice is appreciated.danoc93Sun, 29 Oct 2017 11:41:51 -0500http://answers.opencv.org/question/177170/How to use perspectiveTransformation to convert one image to another when the camera's poses for source and destination images are known?http://answers.opencv.org/question/176687/how-to-use-perspectivetransformation-to-convert-one-image-to-another-when-the-cameras-poses-for-source-and-destination-images-are-known/How to use perspectiveTransformation to convert one image to another?
I could find the example to pickup 4 corresponding points, but in my setting, I can't do that. Instead, I know the camera's poses for both source and destination images.kangarooFri, 20 Oct 2017 02:07:21 -0500http://answers.opencv.org/question/176687/How to determine angular rotation in appropriate directionhttp://answers.opencv.org/question/98348/how-to-determine-angular-rotation-in-appropriate-direction/Hi,
I have this image scanning setup where I am scanning printed papers under a camera. I have this prior information that, when the paper passes under the camera it can rotate upto maximum 5 degrees in either clock wise or counter clock wise direction.
I want to determine the value of the rotation angle in correct direction and then rotate the image back to make it zero degrees. My question is how can I determine the amount of rotation and the correct direction?
thanks
asaWed, 13 Jul 2016 17:47:27 -0500http://answers.opencv.org/question/98348/