Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #313 from amroamroamro/cv310
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
amroamroamro authored Jan 29, 2017
2 parents 678ced7 + 6f98f9a commit ec751cf
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion +cv/BOWImgDescriptorExtractor.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%
% % Compute histogram of visual word occurrences of an image
% extractor = cv.BOWImgDescriptorExtractor('SIFT','BruteForce');
% extractor.setVocabulary(dictionary);
% extractor.Vocabulary = dictionary;
% descs = extractor.compute(im, keypoints);
%
% See also: cv.BOWImgDescriptorExtractor.BOWImgDescriptorExtractor,
Expand Down
2 changes: 1 addition & 1 deletion +cv/BOWKMeansTrainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%
% % Compute histogram of visual word occurrences of an image
% extractor = cv.BOWImgDescriptorExtractor('SIFT','BruteForce');
% extractor.setVocabulary(dictionary);
% extractor.Vocabulary = dictionary;
% descs = extractor.compute(im, keypoints);
%
% ## References
Expand Down
5 changes: 3 additions & 2 deletions +cv/solvePnPRansac.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%SOLVEPNPRANSAC Finds an object pose from 3D-2D point correspondences using the RANSAC scheme
%
% [rvec, tvec, inliers] = cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix)
% [rvec, tvec, success, inliers] = cv.solvePnPRansac(objectPoints, imagePoints, cameraMatrix)
% [...] = cv.solvePnPRansac(..., 'OptionName', optionValue, ...)
%
% ## Input
Expand All @@ -19,7 +19,8 @@
% `tvec`, brings points from the model coordinate system to the
% camera coordinate system.
% * __tvec__ Output translation vector.
% * __inliers__ Output vector that contains indices of inliers in
% * __success__ success logical flag.
% * __inliers__ Output vector that contains indices (zero-based) of inliers in
% `objectPoints` and `imagePoints`.
%
% ## Options
Expand Down
10 changes: 8 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The package provides MATLAB MEX functions that interface with hundreds of
OpenCV APIs. Also the package contains C++ class that converts between
MATLAB's native data type and OpenCV data types. The package is suitable for
fast prototyping of OpenCV application in MATLAB, use of OpenCV as an external
toolbox in MATLAB, and development of a custom MEX function.
toolbox in MATLAB, and development of custom MEX functions.

The current version of mexopencv (master branch) is compatible with OpenCV 3.1.
For older OpenCV versions, please checkout the corresponding branches
Expand Down Expand Up @@ -170,8 +170,14 @@ Replace the path above with the location where OpenCV binaries are installed

Contrib modules are enabled as:

>> addpath('C:\path\to\mexopencv')
>> addpath('C:\path\to\mexopencv\opencv_contrib')
>> mexopencv.make(..., 'opencv_contrib',true)
>> mexopencv.make('opencv_path','C:\OpenCV\build', 'opencv_contrib',true)

If you have previously compiled mexopencv with a different configuration,
don't forget to clean old artifacts build before building:

>> mexopencv.make(..., 'clean',true)

Usage
=====
Expand Down
22 changes: 11 additions & 11 deletions src/+cv/solvePnPRansac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
bool useExtrinsicGuess = false;
int iterationsCount = 100;
float reprojectionError = 8.0f;
double confidence = 0.99;
double confidence = 0.99;
int flags = cv::SOLVEPNP_ITERATIVE;
for (int i=3; i<nrhs; i+=2) {
string key(rhs[i].toString());
Expand Down Expand Up @@ -71,26 +71,26 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
bool success = false;
Mat cameraMatrix(rhs[2].toMat(CV_64F));
if (rhs[0].isNumeric() && rhs[1].isNumeric()) {
Mat objectPoints(rhs[0].toMat(CV_64F).reshape(3,0)),
imagePoints(rhs[1].toMat(CV_64F).reshape(2,0));
Mat objectPoints(rhs[0].toMat(CV_32F).reshape(3,0)),
imagePoints(rhs[1].toMat(CV_32F).reshape(2,0));
success = solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs,
rvec, tvec, useExtrinsicGuess, iterationsCount, reprojectionError,
confidence, (nlhs>2 ? inliers : noArray()), flags);
confidence, (nlhs>3 ? inliers : noArray()), flags);
}
else if (rhs[0].isCell() && rhs[1].isCell()) {
vector<Point3d> objectPoints(rhs[0].toVector<Point3d>());
vector<Point2d> imagePoints(rhs[1].toVector<Point2d>());
vector<Point3f> objectPoints(rhs[0].toVector<Point3f>());
vector<Point2f> imagePoints(rhs[1].toVector<Point2f>());
success = solvePnPRansac(objectPoints, imagePoints, cameraMatrix, distCoeffs,
rvec, tvec, useExtrinsicGuess, iterationsCount, reprojectionError,
confidence, (nlhs>2 ? inliers : noArray()), flags);
confidence, (nlhs>3 ? inliers : noArray()), flags);
}
else
mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
plhs[0] = MxArray(rvec);
plhs[0] = MxArray(rvec.clone()); //HACK, see #309
if (nlhs>1)
plhs[1] = MxArray(tvec);
plhs[1] = MxArray(tvec.clone()); //HACK, see #309
if (nlhs>2)
plhs[2] = MxArray(inliers);
plhs[2] = MxArray(success);
if (nlhs>3)
plhs[3] = MxArray(success);
plhs[3] = MxArray(inliers);
}
2 changes: 1 addition & 1 deletion test/unit_tests/TestSolvePnP.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

methods (Static)
function test_numeric_Nxd
N = 10;
N = 10; % minimum is 4 or 5 points depending on method used
objPoints = rand(N,3);
imgPoints = rand(N,2);
camMatrix = eye(3);
Expand Down
14 changes: 9 additions & 5 deletions test/unit_tests/TestSolvePnPRansac.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
else
n = N;
end
[rvec,tvec,inliers,success] = cv.solvePnPRansac(...
[rvec,tvec,success,inliers] = cv.solvePnPRansac(...
objPoints(1:n,:), imgPoints(1:n,:), camMatrix, ...
'DistCoeffs',distCoeffs, 'Method',methodsPNP{i});
validateattributes(rvec, {'double'}, {'vector', 'numel',3});
Expand All @@ -32,7 +32,8 @@
objPoints = rand(10,1,3);
imgPoints = rand(10,1,2);
camMatrix = eye(3);
[rvec,tvec,inliers,success] = cv.solvePnPRansac(objPoints, imgPoints, camMatrix);
[rvec,tvec,success,inliers] = cv.solvePnPRansac(...
objPoints, imgPoints, camMatrix);
validateattributes(rvec, {'double'}, {'vector', 'numel',3});
validateattributes(tvec, {'double'}, {'vector', 'numel',3});
validateattributes(success, {'logical'}, {'scalar'});
Expand All @@ -46,7 +47,8 @@
objPoints = rand(1,10,3);
imgPoints = rand(1,10,2);
camMatrix = eye(3);
[rvec,tvec,inliers,success] = cv.solvePnPRansac(objPoints, imgPoints, camMatrix);
[rvec,tvec,success,inliers] = cv.solvePnPRansac(...
objPoints, imgPoints, camMatrix);
validateattributes(rvec, {'double'}, {'vector', 'numel',3});
validateattributes(tvec, {'double'}, {'vector', 'numel',3});
validateattributes(success, {'logical'}, {'scalar'});
Expand All @@ -60,7 +62,8 @@
objPoints = num2cell(rand(10,3),2);
imgPoints = num2cell(rand(10,2),2);
camMatrix = eye(3);
[rvec,tvec,inliers,success] = cv.solvePnPRansac(objPoints, imgPoints, camMatrix);
[rvec,tvec,success,inliers] = cv.solvePnPRansac(...
objPoints, imgPoints, camMatrix);
validateattributes(rvec, {'double'}, {'vector', 'numel',3});
validateattributes(tvec, {'double'}, {'vector', 'numel',3});
validateattributes(success, {'logical'}, {'scalar'});
Expand All @@ -76,7 +79,8 @@
camMatrix = eye(3);
rvec = rand(3,1);
tvec = rand(3,1);
[rvec,tvec,inliers,success] = cv.solvePnPRansac(objPoints, imgPoints, camMatrix, ...
[rvec,tvec,success,inliers] = cv.solvePnPRansac(...
objPoints, imgPoints, camMatrix, ...
'Rvec',rvec, 'Tvec',tvec, ...
'UseExtrinsicGuess',true, 'Method','Iterative');
validateattributes(rvec, {'double'}, {'vector', 'numel',3});
Expand Down

0 comments on commit ec751cf

Please sign in to comment.