# Ilan's profile - activity

2018-02-02 08:39:02 -0500 received badge  Famous Question (source)
2017-01-11 09:09:01 -0500 received badge  Notable Question (source)
2016-06-14 21:12:46 -0500 received badge  Popular Question (source)
2014-09-24 13:26:29 -0500 received badge  Self-Learner (source)
2014-08-05 18:26:54 -0500 answered a question Converting a 2D image point to a 3D world point

I succeed to solve it by myself. If it will help to any one, heres the code:

Point3f calc3DPointOutOf2DwithYknown(double u, double v, float worldY, double fx, double fy, double cx, double cy, Mat tvec, Mat rotMat)
{
Point3f tmpPoint;

float r1 = rotMat.at<double>(0,0);
float r2 = rotMat.at<double>(0,1);
float r3 = rotMat.at<double>(0,2);

float r4 = rotMat.at<double>(1,0);
float r5 = rotMat.at<double>(1,1);
float r6 = rotMat.at<double>(1,2);

float r7 = rotMat.at<double>(2,0);
float r8 = rotMat.at<double>(2,1);
float r9 = rotMat.at<double>(2,2);

float t1 = tvec.at<double>(0,0);
float t2 = tvec.at<double>(1,0);
float t3 = tvec.at<double>(2,0);

float xt = (u/fx) - (cx/fx);
float yt = (v/fy) - (cy/fy);

float K1 = xt*r8*worldY + xt*t3 - r2*worldY - t1;
float K2 = xt*r9 - r3;
float K3 = r1 - xt*r7;

float worldZ = (yt*r7*K1 + yt*K3*r8*worldY + yt*K3*t3 - r4*K1 - K3*r5*worldY - K3*t2)/
(r4*K2 + K3*r6 - yt*r7*K2 - yt*K3*r9);

float worldX = (K1 + worldZ*K2)/K3;

tmpPoint = Point3f(worldX, worldY, worldZ);

return tmpPoint;
}

2014-07-25 09:47:57 -0500 asked a question Converting a 2D image point to a 3D world point

I'm developing application for iOS. I'm using the camera matrix according to the book Mastering OpenCV. In my scenario I have a well known box. I know its real dimensions and I know exactly its corner's pixels. Using this information I calculate the camera rotation and the translation vector. From these parameters I'm able to calculate the camera position. I'm checking my calculation by projecting the 3D world coordinate back to the image and I get very accurate results.

The world origin in my case is the middle of the bottom line of the box. The box is open from one side. The image is taken in that direction, so I can see the content of the box.

Now, I have object in the box. I know very well image coordinate (2D) of the corners of this object. I know the real hight of the corner (the real Y and Y <> 0). How do I calculate the world X and Z of the corners of the object.

In this question in the answer by bjoernz he said: "All you can do with the matrices that you have, is to transform a 2D pixel into a 3D line where every point on this line would be projected onto the same 2D pixel.

You will definitely need additional information to reconstruct a 3D point."

I have the real Y (height of the object (40mm)). Also my reference object (the Box) is in the same image.

Here my code:

# include <ctype.h>

using namespace cv; using namespace std;

Point2f point; vector<vector<point2f>> objectPoints(1); vector<vector<point2f>> boxPoints(1);

Point3f calc3DPointOutOf2DwithYknown(double u, double v, float worldY, double fx, double fy, double cx, double cy, Mat tvec, Mat rotMat) { Point3f tmpPoint;

// This fiunction I need to complete
return tmpPoint; }


int main( int argc, char** argv ) {

///////// Loading image
Mat sourceImage = imread("/Users/Ilan/Xcode/LK Test/LK


Test/images/box_center640X480.jpg");

namedWindow( "Source", 1 );

///// Setting box corners /////
point = Point2f((float)102,(float)367.5);


//640X480 boxPoints[0].push_back(point); circle( sourceImage, boxPoints[0][0], 3, Scalar(0,255,0), -1, 8);

point = Point2f((float)83,(float)90.5);


//640X480 boxPoints[0].push_back(point); circle( sourceImage, boxPoints[0][1], 3, Scalar(0,255,0), -1, 8);

point = Point2f((float)520,(float)82.5);


//640X480 boxPoints[0].push_back(point); circle( sourceImage, boxPoints[0][2], 3, Scalar(0,255,0), -1, 8);

point = Point2f((float)510.5,(float)361);


//640X480 boxPoints[0].push_back(point); circle( sourceImage, boxPoints[0][3], 3, Scalar(0,255,0), -1, 8);

///// Setting object corners /////
point = Point2f((float)403.5,(float)250);


//640X480 objectPoints[0].push_back(point); circle( sourceImage, objectPoints[0][0], 3, Scalar(0,255,0), -1, 8);

point = Point2f((float)426.5,(float)251.5);


//640X480 objectPoints[0].push_back(point); circle( sourceImage, objectPoints[0][1], 3, Scalar(0,255,0), -1, 8);

imshow ...
2013-11-11 10:28:54 -0500 commented question exc_bad_access when using Mat in OpenCV although it looks like my indexes are correct

The useless temp++ is only to not get warning of assigning value to unused variable. The exc_bad_access I get it on run time. I don't understand, what is it 'UB'?

2013-11-08 10:01:58 -0500 commented question exc_bad_access when using Mat in OpenCV although it looks like my indexes are correct

The code is copy paste from my code. The only changes are: 1. The number of rows and cols are calculated and not constant numbers (but I run on one example so this are the numbers I get). 2. The loops are in a function and the Mat is created and filled with values out side this function. The Mat src transferred as parameter to the function with the loop. 3. There is a deferent purpose for this function. But because I get this error in the original loop, I comment all the function and did in the function only the code as in my question. So the bottom line is that the exact code I use. Amazing!!! Isn't it?

2013-11-08 09:01:08 -0500 asked a question exc_bad_access when using Mat in OpenCV although it looks like my indexes are correct

I develop some algorithm on Mac using Xcode 5 and OpenCV. I do it as C++.

I define matrix:

Mat src;
int cols = 560;
int rows = 260;
src.create( rows, cols, DataType<double>::type);


In the code I have a loop looks like this:

for (int i=0; i<src.rows; i++) {
const double* srcIterator = src.ptr<double>(i);
for (int j=0; j<src.cols; j++) {
double temp = srcIterator[j];
temp++;
}
}


I read the function that has this loop for every frame I read. Most of the times it runs correctly (it is running in endless loop and it always ok).

In some runs I get exc_bad_access error. When it happened it happened for the first frame. The error is on the line: double temp = srcIterator[j];

When it happened j is much bellow 560 and alway above 500, but each time it has a deferent value.

I thought may be I mix the cols and rows but if it was right I would get this error when j was 260 (the size of rows).

Please, Anyone has any guess what can it be?