I've been trying to understand how to compute a projection matrix using image points and object points (3D and 2D points), but I can't seem to find a clear understanding of how you'd do this. I have a function as follows:
void calculateprojectionmatrix(Mat image_points, Mat object_points, Mat projection_matrix)
I've tried researching solutions for this (preferably in a C++ implementation), but can't find any clear explanation, and no background resources I can find seem to shed enough light on the topic. Any help would be greatly appreciated!
Given that you're using openCV you may want to scan some of the OpenCV docs.
Say, like initCameraMatrix2D ?
You might want to read Find 2D-3D correspondence of 4 non-coplanar points
Related
Doing some research, I found that in Matlab they have this function to create linear structuring elements with a certain angle:
strel('line',len,deg)
The documentations says creates a linear structuring element that is symmetric with respect to the neighborhood center, with approximate length len and angle deg., which basically is a Mat like this with different sizes and angles:
I'm trying to create a similar structuring element in different angles but I couldnt find an equivalent function in Opencv for C++. Is there a way of doing that?
I appreciate any help. Thanks in advance
The closest function OpenCV has is getStructuringElement. Unfortunately, the only shapes it supports are rectangle, cross and ellipse.
Therefore, it is probably the easiest to create/estimate it yourself.
I have a 3D image data obtained from a 3D OCT scan. The data can be represented as I(x,y,z) which means there is an intensity value at each voxel.
I am writing an algorithm which involves finding the image's gradient in x,y and z directions in C++. I've already written a code in C++ using OpenCV for 2D and want to extend it to 3D with minimal changes in my existing code for 2D.
I am familiar with 2D gradients using Sobel or Scharr operators. My search brought me to this post, answers to which recommend ITK and Point Cloud Library. However, these libraries have a lot more functionalities which might not be required. Since I am not very experienced with C++, these libraries require a bit of reading, which time doesn't permit me. Moreover, these libraries don't use cv::Mat object. If I use anything other than cv::Mat, my whole code might have to be changed.
Can anyone help me with this please?
Update 1: Possible solution using kernel separability
Based on #Photon's answer, I'm updating the question.
From what #Photon says, I get an idea of how to construct a Sobel kernel in 3D. However, even if I construct a 3x3x3 cube, how to implement it in OpenCV? The convolution operations in OpenCV using filter2d are only for 2D.
There can be one way. Since the Sobel kernel is separable, it means that we can break the 3D convolution into convolution in lower dimensions. Comments 20 and 21 of this link also tell the same thing. Now, we can separate the 3D kernel but even then filter2D cannot be used since the image is still in 3D. Is there a way to break down the image as well? There is an interesting post which hints at something like this. Any further ideas on this?
Since the Sobel operator is separable, it's easy to envision how to add a 3rd dimension.
For example, when you look at the filter definition for Gx in the link you posted, you see that is multiplies the surrounding pixels by coefficients that have a sign dependent on the relative X position, and magnitude relative to the offset in Y.
When you extend to 3D, the Gx gradient should be calculated the same way, but you need to work on a 3x3x3 cube, and the coefficient sign remains the same definition, and the magnitude now depends on change in either Y or Z or both.
The other gradients (Gy, Gz) are the same but around their axis.
I think I should be using cv::remap to remove the distortion but can't figure out what the the maps const Mat& map1, const Mat& map2 to should be to achieve this.
Should I be using the cv::initUndistortRectifyMap to find out the values? If so, I'd really appreciate an example. I do not have the intrinsic camera parameters or don't know how to calculate them. Thanks.
If you are looking to remove the distortion caused by the camera lens you should take a look at this answer I wrote some time ago, which has intructions and references on how to do proper camera calibration.
I also suggest this post, which has good info on the procedure as well and uses the C++ interface of OpenCV.
I am rather new to C++ and openframeworks. I am beginning to play with manipulating objects using the Lucas Kanade technique. I am having some success with pushing objects around but unfortunately I cannot figure out how to go about rotating them properly or even detect when rotational movement is occurring for that matter.
Does anyone have any pointers or tips they would like to share?
Many thanks,
N
Optical flow calculations won't on their own help you detect things like "rotational movement". Basically, all the optical flow calc is doing is looking at changes pixel-by-pixel, while what you mean by rotation is a larger aggregate of pixel change. An algorithm would need to detect something like "all the pixels on the edge of the object are flowing in a (counter-)clockwise direction". Very difficult to do, and I don't think there's anything in OpenFrameworks or OpenCV that will help you.
Are you trying to detect rotation of an object in the image, or rotation-like movements in the image that will affect a virtual object? If it's the former, I think there are OpenCV techniques for identifying objects and then tracking them, including things like rotation. I think the things to research are like "opencv object tracking" and "opencv object motion analysis".
To compute the 2x3 affine transformation matrix of your motion could be a solution. The affine transformation matrix contains tranlational and rotational movements as far as scaling. If you are using OpenCV than cv::getAffineTransform is what you are looking for where you can directly input the tracked feature points.
Papers have been written describing how the Hough transform can be generalised to detect shapes like circles and parabolas. I'm new to computer vision though and find these papers pretty tough going. There is also code out there that does this detection but this is more than I want. I was wondering if anyone could briefly describe in bullet points or pseudo-code really simply how Hough Transforms are used to detect parabolas in images. That would be amazing. Or if anyone knows any basic explanations online that I haven't come across than that would be good enough too :).
Thanks very much :).
Interesting question. This looks like a great resource. I included a summary (loosely quoted). Also see the source from Mathworks at the bottom of this answer - Matlab has houghlines and houghpeaks functions which will be useful for you. Hope it helps.
Run edge detection algorithm, such as the Canny edge detector, on subject image
Input edge/boundary points into Hough Transform (line detecting)
Generate a curve in polar space (radius, angle) for each point
in Cartesian space (also called
accumulator array)
Extract local maxima from the accumulator array, for example using a
relative threshold
In other words, we take only those local maxima in the accumulator
array whose values are equal to or
greater than some fixed percentage of
the global maximum value.
De-Houghing into Cartesian space yields a set of line descriptions of the image subject
cs.jhu.edu:
http://www.cs.jhu.edu/~misha/Fall04/GHT1.pdf
Code from Mathworks: http://www.mathworks.com/help/toolbox/images/ref/hough.html