mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
code clean up
This commit is contained in:
parent
78bd55c8df
commit
794c14b29a
@ -160,7 +160,7 @@ void CirclesGridClusterFinder::findGrid(const std::vector<cv::Point2f> &points,
|
||||
#endif
|
||||
|
||||
std::vector<Point2f> hull2f;
|
||||
convexHull(Mat(patternPoints), hull2f, false);
|
||||
convexHull(patternPoints, hull2f, false);
|
||||
const size_t cornersCount = isAsymmetricGrid ? 6 : 4;
|
||||
if(hull2f.size() < cornersCount)
|
||||
return;
|
||||
@ -411,7 +411,7 @@ void CirclesGridClusterFinder::rectifyPatternPoints(const std::vector<cv::Point2
|
||||
}
|
||||
}
|
||||
|
||||
Mat homography = findHomography(Mat(sortedCorners), Mat(idealPoints), 0);
|
||||
Mat homography = findHomography(sortedCorners, idealPoints, 0);
|
||||
Mat rectifiedPointsMat;
|
||||
transform(patternPoints, rectifiedPointsMat, homography);
|
||||
rectifiedPatternPoints.clear();
|
||||
@ -871,8 +871,8 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
|
||||
}
|
||||
}
|
||||
|
||||
Mat H = findHomography(Mat(centers), Mat(dstPoints), RANSAC);
|
||||
//Mat H = findHomography( Mat( corners ), Mat( dstPoints ) );
|
||||
Mat H = findHomography(centers, dstPoints, RANSAC);
|
||||
//Mat H = findHomography(corners, dstPoints);
|
||||
|
||||
if (H.empty())
|
||||
{
|
||||
@ -888,7 +888,7 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
|
||||
}
|
||||
|
||||
Mat dstKeypointsMat;
|
||||
transform(Mat(srcKeypoints), dstKeypointsMat, H);
|
||||
transform(srcKeypoints, dstKeypointsMat, H);
|
||||
std::vector<Point2f> dstKeypoints;
|
||||
convertPointsFromHomogeneous(dstKeypointsMat, dstKeypoints);
|
||||
|
||||
@ -1176,7 +1176,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
|
||||
}
|
||||
for (size_t i = 0; i < basis.size(); i++)
|
||||
{
|
||||
convexHull(Mat(clusters[i]), hulls[i]);
|
||||
convexHull(clusters[i], hulls[i]);
|
||||
}
|
||||
|
||||
basisGraphs.resize(basis.size(), Graph(keypoints.size()));
|
||||
@ -1191,7 +1191,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
|
||||
|
||||
for (size_t k = 0; k < hulls.size(); k++)
|
||||
{
|
||||
if (pointPolygonTest(Mat(hulls[k]), vec, false) >= 0)
|
||||
if (pointPolygonTest(hulls[k], vec, false) >= 0)
|
||||
{
|
||||
basisGraphs[k].addEdge(i, j);
|
||||
}
|
||||
@ -1422,7 +1422,6 @@ void CirclesGridFinder::drawHoles(const Mat &srcImage, Mat &drawImage) const
|
||||
if (i != holes.size() - 1)
|
||||
line(drawImage, keypoints[holes[i][j]], keypoints[holes[i + 1][j]], Scalar(255, 0, 0), 2);
|
||||
|
||||
//circle(drawImage, keypoints[holes[i][j]], holeRadius, holeColor, holeThickness);
|
||||
circle(drawImage, keypoints[holes[i][j]], holeRadius, holeColor, holeThickness);
|
||||
}
|
||||
}
|
||||
|
@ -194,9 +194,8 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count);
|
||||
|
||||
std::vector<std::vector<Point> > white_contours, black_contours;
|
||||
std::vector<Vec4i> white_hierarchy, black_hierarchy;
|
||||
findContours(black_comp, black_contours, black_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
findContours(white_comp, white_contours, white_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
findContours(black_comp, black_contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
findContours(white_comp, white_contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
if(black_contours.size() < 5 || white_contours.size() < 5) continue;
|
||||
|
||||
|
@ -1514,7 +1514,7 @@ bool CV_StereoCalibrationTest::checkPandROI( int test_case_idx, const Mat& M, co
|
||||
for( x = 0; x < N; x++ )
|
||||
pts.push_back(Point2f((float)x*imgsize.width/(N-1), (float)y*imgsize.height/(N-1)));
|
||||
|
||||
undistortPoints(Mat(pts), upts, M, D, R, P );
|
||||
undistortPoints(pts, upts, M, D, R, P );
|
||||
for( k = 0; k < N*N; k++ )
|
||||
if( upts[k].x < -imgsize.width*eps || upts[k].x > imgsize.width*(1+eps) ||
|
||||
upts[k].y < -imgsize.height*eps || upts[k].y > imgsize.height*(1+eps) )
|
||||
@ -1823,8 +1823,8 @@ void CV_StereoCalibrationTest::run( int )
|
||||
for( int i = 0, k = 0; i < nframes; i++ )
|
||||
{
|
||||
vector<Point2f> temp[2];
|
||||
undistortPoints(Mat(imgpt1[i]), temp[0], M1, D1, R1, P1);
|
||||
undistortPoints(Mat(imgpt2[i]), temp[1], M2, D2, R2, P2);
|
||||
undistortPoints(imgpt1[i], temp[0], M1, D1, R1, P1);
|
||||
undistortPoints(imgpt2[i], temp[1], M2, D2, R2, P2);
|
||||
|
||||
for( int j = 0; j < npoints; j++, k++ )
|
||||
{
|
||||
|
@ -353,7 +353,7 @@ protected:
|
||||
rvecs_spnp.resize(brdsNum);
|
||||
tvecs_spnp.resize(brdsNum);
|
||||
for(size_t i = 0; i < brdsNum; ++i)
|
||||
solvePnP(Mat(objectPoints[i]), Mat(imagePoints[i]), camMat, distCoeffs, rvecs_spnp[i], tvecs_spnp[i]);
|
||||
solvePnP(objectPoints[i], imagePoints[i], camMat, distCoeffs, rvecs_spnp[i], tvecs_spnp[i]);
|
||||
|
||||
compareShiftVecs(tvecs_exp, tvecs_spnp);
|
||||
compareRotationVecs(rvecs_exp, rvecs_spnp);
|
||||
|
@ -126,10 +126,10 @@ Mat ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat, co
|
||||
generateEdge(p3, p4, pts_square3d);
|
||||
generateEdge(p4, p1, pts_square3d);
|
||||
|
||||
projectPoints(Mat(pts_square3d), rvec, tvec, camMat, distCoeffs, pts_square2d);
|
||||
projectPoints(pts_square3d, rvec, tvec, camMat, distCoeffs, pts_square2d);
|
||||
squares_black.resize(squares_black.size() + 1);
|
||||
vector<Point2f> temp;
|
||||
approxPolyDP(Mat(pts_square2d), temp, 1.0, true);
|
||||
approxPolyDP(pts_square2d, temp, 1.0, true);
|
||||
transform(temp.begin(), temp.end(), back_inserter(squares_black.back()), Mult(rendererResolutionMultiplier));
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ Mat ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat, co
|
||||
for(int i = 0; i < patternSize.width - 1; ++i)
|
||||
corners3d.push_back(zero + (i + 1) * sqWidth * pb1 + (j + 1) * sqHeight * pb2);
|
||||
corners.clear();
|
||||
projectPoints(Mat(corners3d), rvec, tvec, camMat, distCoeffs, corners);
|
||||
projectPoints(corners3d, rvec, tvec, camMat, distCoeffs, corners);
|
||||
|
||||
vector<Point3f> whole3d;
|
||||
vector<Point2f> whole2d;
|
||||
@ -147,9 +147,9 @@ Mat ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat, co
|
||||
generateEdge(whole[1], whole[2], whole3d);
|
||||
generateEdge(whole[2], whole[3], whole3d);
|
||||
generateEdge(whole[3], whole[0], whole3d);
|
||||
projectPoints(Mat(whole3d), rvec, tvec, camMat, distCoeffs, whole2d);
|
||||
projectPoints(whole3d, rvec, tvec, camMat, distCoeffs, whole2d);
|
||||
vector<Point2f> temp_whole2d;
|
||||
approxPolyDP(Mat(whole2d), temp_whole2d, 1.0, true);
|
||||
approxPolyDP(whole2d, temp_whole2d, 1.0, true);
|
||||
|
||||
vector< vector<Point > > whole_contour(1);
|
||||
transform(temp_whole2d.begin(), temp_whole2d.end(),
|
||||
@ -213,7 +213,7 @@ Mat ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
projectPoints(pts3d, rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
bool inrect1 = pts2d[0].x < bg.cols && pts2d[0].y < bg.rows && pts2d[0].x > 0 && pts2d[0].y > 0;
|
||||
bool inrect2 = pts2d[1].x < bg.cols && pts2d[1].y < bg.rows && pts2d[1].x > 0 && pts2d[1].y > 0;
|
||||
@ -278,7 +278,7 @@ Mat ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
projectPoints(pts3d, rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
bool inrect1 = pts2d[0].x < bg.cols && pts2d[0].y < bg.rows && pts2d[0].x > 0 && pts2d[0].y > 0;
|
||||
bool inrect2 = pts2d[1].x < bg.cols && pts2d[1].y < bg.rows && pts2d[1].x > 0 && pts2d[1].y > 0;
|
||||
@ -320,7 +320,7 @@ Mat ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const Mat
|
||||
pts3d[3] = p - pb1 * cbHalfWidthEx + cbHalfHeightEx * pb2;
|
||||
|
||||
/* can remake with better perf */
|
||||
projectPoints(Mat(pts3d), rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
projectPoints(pts3d, rvec, tvec, camMat, distCoeffs, pts2d);
|
||||
|
||||
Point3f zero = p - pb1 * cbHalfWidth - cbHalfHeight * pb2;
|
||||
|
||||
|
@ -124,7 +124,7 @@ protected:
|
||||
|
||||
vector<Point2f> projectedPoints;
|
||||
projectedPoints.resize(points.size());
|
||||
projectPoints(Mat(points), trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
projectPoints(points, trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
for (size_t i = 0; i < projectedPoints.size(); i++)
|
||||
{
|
||||
if (i % 20 == 0)
|
||||
@ -241,7 +241,7 @@ protected:
|
||||
|
||||
vector<Point2f> projectedPoints;
|
||||
projectedPoints.resize(opoints.size());
|
||||
projectPoints(Mat(opoints), trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
projectPoints(opoints, trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
|
||||
bool isEstimateSuccess = solvePnP(opoints, projectedPoints, intrinsics, distCoeffs, rvec, tvec, false, method);
|
||||
if (isEstimateSuccess == false)
|
||||
@ -291,7 +291,7 @@ class CV_solveP3P_Test : public CV_solvePnPRansac_Test
|
||||
|
||||
vector<Point2f> projectedPoints;
|
||||
projectedPoints.resize(opoints.size());
|
||||
projectPoints(Mat(opoints), trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
projectPoints(opoints, trueRvec, trueTvec, intrinsics, distCoeffs, projectedPoints);
|
||||
|
||||
int num_of_solutions = solveP3P(opoints, projectedPoints, intrinsics, distCoeffs, rvecs, tvecs, method);
|
||||
if (num_of_solutions != (int) rvecs.size() || num_of_solutions != (int) tvecs.size() || num_of_solutions == 0)
|
||||
|
@ -197,8 +197,7 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
|
||||
centers.clear();
|
||||
|
||||
std::vector < std::vector<Point> > contours;
|
||||
Mat tmpBinaryImage = binaryImage.clone();
|
||||
findContours(tmpBinaryImage, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
||||
findContours(binaryImage, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
||||
|
||||
#ifdef DEBUG_BLOB_DETECTOR
|
||||
// Mat keypointsImage;
|
||||
@ -214,7 +213,7 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
|
||||
{
|
||||
Center center;
|
||||
center.confidence = 1;
|
||||
Moments moms = moments(Mat(contours[contourIdx]));
|
||||
Moments moms = moments(contours[contourIdx]);
|
||||
if (params.filterByArea)
|
||||
{
|
||||
double area = moms.m00;
|
||||
@ -225,7 +224,7 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
|
||||
if (params.filterByCircularity)
|
||||
{
|
||||
double area = moms.m00;
|
||||
double perimeter = arcLength(Mat(contours[contourIdx]), true);
|
||||
double perimeter = arcLength(contours[contourIdx], true);
|
||||
double ratio = 4 * CV_PI * area / (perimeter * perimeter);
|
||||
if (ratio < params.minCircularity || ratio >= params.maxCircularity)
|
||||
continue;
|
||||
@ -261,9 +260,9 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
|
||||
if (params.filterByConvexity)
|
||||
{
|
||||
std::vector < Point > hull;
|
||||
convexHull(Mat(contours[contourIdx]), hull);
|
||||
double area = contourArea(Mat(contours[contourIdx]));
|
||||
double hullArea = contourArea(Mat(hull));
|
||||
convexHull(contours[contourIdx], hull);
|
||||
double area = contourArea(contours[contourIdx]);
|
||||
double hullArea = contourArea(hull);
|
||||
if (fabs(hullArea) < DBL_EPSILON)
|
||||
continue;
|
||||
double ratio = area / hullArea;
|
||||
|
@ -387,7 +387,7 @@ bool QRDetect::computeTransformationPoints()
|
||||
findNonZero(mask_roi, non_zero_elem[i]);
|
||||
newHull.insert(newHull.end(), non_zero_elem[i].begin(), non_zero_elem[i].end());
|
||||
}
|
||||
convexHull(Mat(newHull), locations);
|
||||
convexHull(newHull, locations);
|
||||
for (size_t i = 0; i < locations.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < 3; j++)
|
||||
@ -556,7 +556,7 @@ vector<Point2f> QRDetect::getQuadrilateral(vector<Point2f> angle_list)
|
||||
}
|
||||
|
||||
vector<Point> integer_hull;
|
||||
convexHull(Mat(locations), integer_hull);
|
||||
convexHull(locations, integer_hull);
|
||||
int hull_size = (int)integer_hull.size();
|
||||
vector<Point2f> hull(hull_size);
|
||||
for (int i = 0; i < hull_size; i++)
|
||||
@ -910,7 +910,7 @@ bool QRDecode::versionDefinition()
|
||||
vector<Point> locations, non_zero_elem;
|
||||
Mat mask_roi = mask(Range(1, intermediate.rows - 1), Range(1, intermediate.cols - 1));
|
||||
findNonZero(mask_roi, non_zero_elem);
|
||||
convexHull(Mat(non_zero_elem), locations);
|
||||
convexHull(non_zero_elem, locations);
|
||||
Point offset = computeOffset(locations);
|
||||
|
||||
Point temp_remote = locations[0], remote_point;
|
||||
|
Loading…
Reference in New Issue
Block a user