OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Tue, 25 Aug 2020 13:16:56 -0500result coordinate typehttp://answers.opencv.org/question/234253/result-coordinate-type/ I have been making intersection point calculations between parametric line eqs and planes in opencv. I am using raw imaging point data for the math calculations below. What units of measurement are my results? I haven't done a opencv Rodriquez, transformation or other function on this data set yet, otherwise the question would be settled.
I've also tried "converting" to U, V coordinates but am unsure if its correct.
double numer = plane.get_numer(d, n, Ro); // origin point - p - see diagram
double denom = plane.get_denom(n, Rd);
double t = numer / denom;
Vec3d IP = plane.get_IP(Ro, Rd, t); // IP = 'intersection point'
double U = CV_FX * IP[0] + CV_CX;
double V = CV_FY * IP[1] + CV_CY;
std::cout << "U,V = " << U << "," << V << std::endl;superflyTue, 25 Aug 2020 13:16:56 -0500http://answers.opencv.org/question/234253/why invert posehttp://answers.opencv.org/question/232411/why-invert-pose/ I have a pose output from solvepnp(), not a prob. Many sources suggest to take the inverse of the pose. I am having a contextual blindspot here: can someone tell me why I should use the inverted pose. In common sense language how is the inverted coordinate space more accurate/more appropriate.superflySun, 12 Jul 2020 13:15:56 -0500http://answers.opencv.org/question/232411/4 x 4 or 3 x 4 format?http://answers.opencv.org/question/229625/4-x-4-or-3-x-4-format/I have a 3 x 4 matrix of -R|t information. Seems fine. However I came across an exercise where a bottom layer of '0 0 0 1'
was added across the bottom of said matrix. For me to change this would create a cascading change effect on every matrix dependent on it. What should I be doing?
Which is the correct configuration
4 x 4
[0 1 0 tx;
1 2 1 ty
1 1 2 tz
0 0 0 1]
or
3 x 4
[0 1 0 tx
1 2 1 ty
1 1 2 tz]
enter code heresuperflyTue, 28 Apr 2020 12:57:32 -0500http://answers.opencv.org/question/229625/multiplying homography and image matriceshttp://answers.opencv.org/question/228558/multiplying-homography-and-image-matrices/I have been trying to understand how warpPerspective() is working.
I understand that among other things it multiplies the homography matrix by the source image matrix.
I have the source image matrix generated by
Mat img_src = imread(imageName, IMREAD_GRAYSCALE);
and the homography matrix generated by
Mat h = findHomography(pts_src, pts_dst);
where pts_src and pts_dst are filled using four point each
pts_dst.push_back(Point2f(0,0));
This works well with warpPerspective(), but the code
Mat im=h*img_src;
imshow("Image", im);
compiles well, yet imshow("Image", im) generates an error:
Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
I guess this is probably type mismatch between img_src and h which seems to be of type double because only
cout << h.at<double>(i,j) << endl;
works on it.
How could be this sorted out?andrei186Sun, 05 Apr 2020 11:52:16 -0500http://answers.opencv.org/question/228558/How to append a Mat to another Mathttp://answers.opencv.org/question/194231/how-to-append-a-mat-to-another-mat/I have the following two `Matrices`
Mat [ 1764*1*CV_32FC1 ]
Mat [ 2*4*CV_32FC1]
I want to append them in one `Mat` so that it will have only one `row` so i can train `SVM`MachoThu, 21 Jun 2018 07:07:45 -0500http://answers.opencv.org/question/194231/How to get pixel's value from a picture?http://answers.opencv.org/question/12963/how-to-get-pixels-value-from-a-picture/Hi guys,
I intend to get the pixel value from a picture, but I don't know how to do that, can someone help me please?
I have already loaded and resized an image, now I would like to get the pixel value from the new image and print it, probably I will need to use Matrices, but I don't know how. I would like to get the RGB pixel value and differentiate it in a matrix for each color ( Red, Green and Blue).
I would appreciate it if someone could help me with a sample code.
My code to load and resize the image is that:
#include <opencv\cv.h>
#include <opencv\highgui.h>
int main()
{
cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );
IplImage* img = cvLoadImage("Koala.jpg");
cvShowImage("original:",img);
CvSize size = cvSize(800, 600);
IplImage* tmpsize=cvCreateImage(size, img->depth, img->nChannels);
cvResize(img,tmpsize,CV_INTER_LINEAR);
cvShowImage("new",tmpsize);
cvWaitKey(0);
return 0;
}
Thank you,
Jack.Jack ChungMon, 06 May 2013 11:53:39 -0500http://answers.opencv.org/question/12963/Mat pointerhttp://answers.opencv.org/question/143663/mat-pointer/How do I create a vector of Mat pointers ? In the code below, I want to read the yaml files into the matrices `K_00, K_01`, etc
//initialize camera params
cv::Mat K_00, K_01, D_00, D_01, R, Tr;
std::vector<cv::Mat> camera_params = { K_00, K_01, D_00, D_01, R, T };
std::vector<std::string> camera_params_name = { "K_00", "K_01", "D_00", "D_01", "R", "T"};
for (int i = 0; i < camera_params.size(); i++)
{
cv::FileStorage fs;
fs.open(root + camera_params_name[i] + ".yaml", cv::FileStorage::READ);
fs[camera_params_name[i]] >> camera_params[i];
}
//error K_00, K_01, etc. are all empty
stereoRectify(K_00, cv::Mat(), K_01, ....); // I want to use K_00, etc. instead of
// camera_params[0]
NbbMon, 24 Apr 2017 23:41:38 -0500http://answers.opencv.org/question/143663/efficient access of matriceshttp://answers.opencv.org/question/136410/efficient-access-of-matrices/I know I can access matrices in 2 ways, http://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html
Either using `Mat.at<uchar>(row,col)` or using the method below. My question is, if I am using Visual Studio and am targetting real-time applications. Will there be a difference between the two methods ? Visual Studio has a *release* build so I am not sure if accessing matrices becomes a lot more optimized.
Mat& ScanImageAndReduceC(Mat& I, const uchar* const table)
{
// accept only char type matrices
CV_Assert(I.depth() == CV_8U);
int channels = I.channels();
int nRows = I.rows;
int nCols = I.cols * channels;
if (I.isContinuous())
{
nCols *= nRows;
nRows = 1;
}
int i,j;
uchar* p;
for( i = 0; i < nRows; ++i)
{
p = I.ptr<uchar>(i);
for ( j = 0; j < nCols; ++j)
{
p[j] = table[p[j]];
}
}
return I;
}NbbTue, 28 Mar 2017 04:27:00 -0500http://answers.opencv.org/question/136410/memory deallocationhttp://answers.opencv.org/question/103108/memory-deallocation/ OpenCV matrices can be declared in various ways. I am looking to declare openCV matrices in a main class and then populate them in member functions.
My question : I believe that openCV matrices will be deallocated automatically once the main class object goes out of scope !! Which means that I do not have to manually call release function of openCV matrices
Please correct me if I am wrong
ThanksNabeelTue, 27 Sep 2016 15:06:02 -0500http://answers.opencv.org/question/103108/OpenCV optimisation - multiplying a set of matrices by a set of scalars and summing.http://answers.opencv.org/question/91608/opencv-optimisation-multiplying-a-set-of-matrices-by-a-set-of-scalars-and-summing/I have an optimisation problem and I'm wondering what the best way to approach the problem is.
At present I have a set of matrices (*mats*) that I need to scale by a set of values held in a vector and then summed together. I have written the following code nut it seems to be pretty painfully slow (far more so than I would have thought).
cv::Mat sum = cv::Mat::zeros( mats[0].rows, mats[0].cols, cvType );
for( int m = 0; m < mats.size(); m++ )
{
const Type val = rowVec.at< Type >( m );
sum += val * mats[m];
}
Can anyone suggest a faster way of doing the above loop?
***Edit:***
I wrote a little function to try and aid my performance:
template< typename Type >
void ScaleMatAndSum( cv::Mat& scale, const cv::Mat& mats, const Type val )
{
for( int r = 0; r < mats.rows; r++ )
{
for( int c = 0; c < mats.cols; c++ )
{
scale.at< Type >( r, c ) += mats.at< Type >( r, c ) * val;
}
}
}
This is about 8 times faster when multi-threaded than the original code. Can anyone explain what is going on?GozFri, 01 Apr 2016 05:50:16 -0500http://answers.opencv.org/question/91608/Stereo calibration: problem with projection matrices and SGBMhttp://answers.opencv.org/question/27508/stereo-calibration-problem-with-projection-matrices-and-sgbm/I am trying to create a depth map from a disparity using SGBM. The resulting disparity map has almost no definition. So I set up sliders for the various SGBM values and can get very limited results - they are basically blank.
After calibrating the cameras individually followed by the stereo calibration I can rectify images which comes out rather well:
![rectified image](/upfiles/13911306844204794.jpg)
Something I've noticed is the projection matrices and the Q matrix have several NAN values. Also the ROI for each camera is all zeros which can['t be right. Below are the saved calibration setting that I am using showing the NAN values.
Since the RMS values for each single camera calibration are under 0.4 and the stereo RMS is less than 2.0 with a re-projection error of less then 4.0 I'm not sure what may be wrong at this point. Suggestions and help would be greatly appreciated.
Camera_0_Matrix<br>
8.2360702625110662e+002 0. 3.1410424020211406e+002<br>
0. 8.1860608380736392e+002 2.4384904263053622e+002<br>
0. 0. 1.<br>
Camera_1_Matrix<br>
8.1134698384868875e+002 0. 3.1328331721626449e+002<br>
0. 8.0724997468627953e+002 2.3930244099756220e+002<br>
0. 0. 1.<br>
Camera_0_Distortion_Coefficients<br>
2.6712887348238189e-002 -1.8664642728347297e-001<br>
-4.8596016262543446e-004 -1.4728080493686517e-003<br>
5.2687479496305778e-001 0. 0. 0.<br>
Camera_1_Distortion_Coefficients<br>
3.9590803660099684e-002 -1.8981006469293660e-001<br>
-6.4688587632222173e-003 -3.7797348771147284e-003<br>
2.7996253215102412e-001 0. 0. 0.<br>
Mat_R<br>
9.9922618707330479e-001 -1.4827571495127988e-002 -3.6430347109269276e-002<br>
1.4533977386417006e-002 9.9985983789215160e-001 -8.3107202823446188e-003<br>
3.6548468754191266e-002 7.7748114984945516e-003 9.9930163701351293e-001<br>
Mat_T<br>
-7.1373089613768613e+001 -6.5822496464438818e-001 -6.3515467302110000e+000<br>
Mat_E<br>
6.8256121992123484e-002 6.3455389090094831e+000 -7.1055121292732304e-001 <br>
-3.7380546856077390e+000 6.4909033105906033e-001 7.1554634341813454e+001<br>
-3.7961924878715458e-001 -7.1372845688807843e+001 5.6918241952876536e-001<br>
Mat_F<br>
7.2342254670288030e-008 6.7664989166222400e-006 -2.2929759854297700e-003 <br>
-3.9819395869095442e-006 6.9566352175857590e-007 6.3859013286650543e-002<br>
6.0378280400693674e-004 -6.4036046720140641e-002 1.<br>
Camera_0_Rotation_Matrix<br>
9.9862396895832117e-001 -4.8951125057362125e-003 5.2213087396614198e-002 <br>
5.1174999253298069e-003 9.9997839183290060e-001 -4.1263860459532032e-003<br>
-5.2191760043559916e-002 4.3879084815174659e-003 9.9862744126261294e-001<br>
Camera_1_Rotation_Matrix<br>
9.9602166255538394e-001 9.1856234214931377e-003 8.8636742058627288e-002 <br>
-9.5633854847882640e-003 9.9994690362209304e-001 3.8381759545177280e-003<br>
-8.8596779729730887e-002 -4.6705737278212095e-003 9.9605662307048315e-001<br>
Camera_0_Projection_Matrix<br>
.Nan 0. .Nan 0.<br>
0. .Nan .Nan 0.<br>
0. 0. 1. 0.<br>
Camera_1_Projection_Matrix<br>
.Nan 0. .Nan .Nan <br>
0. .Nan .Nan 0. <br>
0. 0. 1. 0.<br>
Mat_Q<br>
1. 0. 0. .Nan <br>
0. 1. 0. .Nan <br>
0. 0. 0. .Nan <br>
0. 0. 1.3955142868906164e-002 .Nan<br>
ROI_0<br>
0 0 0 0<br>
ROI_1<br>
0 0 0 0<br>
jim_73_mk1Thu, 30 Jan 2014 19:52:39 -0600http://answers.opencv.org/question/27508/How can I write pixel value in matrices?http://answers.opencv.org/question/18913/how-can-i-write-pixel-value-in-matrices/Hello,
How can I write a value in a matrice?
I already created a matrice, read a binary image and get the pixel value, now I would like to write the pixel value in the matrice.
I would appreciate it if someone could help me to set the pixel value in the matrice.
The code that I read a binary image and try to write the pixel value in the matrice is:
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
uchar binario, valor;
if(fp == NULL){
printf("\nNĂ£o encontrei arquivo\n");
exit(EXIT_FAILURE);
}
CvMat* polar = cvCreateMat(20, 172, CV_8UC1);
cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "new", CV_WINDOW_AUTOSIZE );
IplImage* src = cvLoadImage("Koala.jpg", CV_LOAD_IMAGE_GRAYSCALE);
cvShowImage("original", src);
CvSize size = cvSize(40, 40);
IplImage* resize = cvCreateImage(size, src->depth, src->nChannels);
cvResize(src, resize, CV_INTER_LINEAR);
IplImage* img_binario = cvCreateImage(cvGetSize(resize), IPL_DEPTH_8U, 1);
cvThreshold(resize, img_binario, 100, 255, CV_THRESH_BINARY);
for(int i = 0; i < 20; i++){
//*((uchar*)CV_MAT_ELEM_PTR(*polar, i, 1)) = ((uchar *)(img_binario->imageData + i*img_binario->widthStep))[20];
cvSet2D(polar, i, 1, ((uchar *)(img_binario->imageData + i*img_binario->widthStep))[20]);
}
printf("Valor: %i", polar);
cvShowImage("new", img_binario);
cvWaitKey(0);
return 0;
}
Thank you.
Jack ChungThu, 15 Aug 2013 10:03:21 -0500http://answers.opencv.org/question/18913/Compute the orthonormal basis of a matrixhttp://answers.opencv.org/question/15222/compute-the-orthonormal-basis-of-a-matrix/Hello,
I need to find the orthonormal basis for range of a matrix, basically [this function](http://www.mathworks.com/help/symbolic/orth.html)
However, I haven't found anything that provides this capability in opencv.
I've tried working with cvSVD, but my results aren't correct.
Any clues?dwbritoSat, 15 Jun 2013 12:43:33 -0500http://answers.opencv.org/question/15222/Reshaping matrices into column vectors??http://answers.opencv.org/question/13658/reshaping-matrices-into-column-vectors/Hi,
I have a question regarding reshaping matrices. I have two square 3x3 matrices M1 and M2. I wish to turn both matrices into 9 element column vectors c1 and c2. Next i would like to create a new matrix consisting of new 2x9 matrix [c1,c2]. I need to do this in order to solve a least square problem.
I tried using the reshape function as M1.reshape(0,9) but it returns:
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshapenapoleonTue, 21 May 2013 16:04:40 -0500http://answers.opencv.org/question/13658/problem with reprojection matriceshttp://answers.opencv.org/question/12875/problem-with-reprojection-matrices/Hi,
i'm trying to rectify my images before doing the 3d reconstruction. while using cvstereorectify i got in the projection matrices P1 and P2 an negative value for c_x_1 and c_x_2.
How can it be that i got negative values? The epipolar lines look really good.
Thank you.
bastiSat, 04 May 2013 09:27:33 -0500http://answers.opencv.org/question/12875/