Merge pull request #11703 from alalek:c_api_calib3d_chessboard_detector

pull/11925/head^2
Alexander Alekhin 6 years ago
commit 7ba66a1682
  1. 47
      modules/calib3d/src/calib3d_c_api.cpp
  2. 1728
      modules/calib3d/src/calibinit.cpp
  3. 6
      modules/calib3d/src/precomp.hpp
  4. 3
      modules/calib3d/test/test_cameracalibration.cpp
  5. 24
      modules/core/include/opencv2/core/types_c.h
  6. 12
      modules/ts/src/ts.cpp

@ -0,0 +1,47 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// This file contains wrappers for legacy OpenCV C API
#include "precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"
using namespace cv;
CV_IMPL void
cvDrawChessboardCorners(CvArr* _image, CvSize pattern_size,
CvPoint2D32f* corners, int count, int found)
{
CV_Assert(corners != NULL); //CV_CheckNULL(corners, "NULL is not allowed for 'corners' parameter");
Mat image = cvarrToMat(_image);
CV_StaticAssert(sizeof(CvPoint2D32f) == sizeof(Point2f), "");
drawChessboardCorners(image, pattern_size, Mat(1, count, traits::Type<Point2f>::value, corners), found != 0);
}
CV_IMPL int
cvFindChessboardCorners(const void* arr, CvSize pattern_size,
CvPoint2D32f* out_corners_, int* out_corner_count,
int flags)
{
if (!out_corners_)
CV_Error( CV_StsNullPtr, "Null pointer to corners" );
Mat image = cvarrToMat(arr);
std::vector<Point2f> out_corners;
if (out_corner_count)
*out_corner_count = 0;
bool res = cv::findChessboardCorners(image, pattern_size, out_corners, flags);
int corner_count = (int)out_corners.size();
if (out_corner_count)
*out_corner_count = corner_count;
CV_CheckLE(corner_count, Size(pattern_size).area(), "Unexpected number of corners");
for (int i = 0; i < corner_count; ++i)
{
out_corners_[i] = cvPoint2D32f(out_corners[i]);
}
return res ? 1 : 0;
}

File diff suppressed because it is too large Load Diff

@ -42,12 +42,14 @@
#ifndef __OPENCV_PRECOMP_H__ #ifndef __OPENCV_PRECOMP_H__
#define __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/calib3d.hpp" #include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#include "opencv2/features2d.hpp" #include "opencv2/features2d.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/core/ocl.hpp" #include "opencv2/core/ocl.hpp"

@ -1618,7 +1618,8 @@ void CV_StereoCalibrationTest::run( int )
bool found2 = findChessboardCorners(right, patternSize, imgpt2[i]); bool found2 = findChessboardCorners(right, patternSize, imgpt2[i]);
if(!found1 || !found2) if(!found1 || !found2)
{ {
ts->printf( cvtest::TS::LOG, "The function could not detect boards on the images %s and %s, testcase %d\n", ts->printf( cvtest::TS::LOG, "The function could not detect boards (%d x %d) on the images %s and %s, testcase %d\n",
patternSize.width, patternSize.height,
imglist[i*2].c_str(), imglist[i*2+1].c_str(), testcase ); imglist[i*2].c_str(), imglist[i*2+1].c_str(), testcase );
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
return; return;

@ -409,6 +409,11 @@ IplConvKernelFP;
#define CV_MAT_MAGIC_VAL 0x42420000 #define CV_MAT_MAGIC_VAL 0x42420000
#define CV_TYPE_NAME_MAT "opencv-matrix" #define CV_TYPE_NAME_MAT "opencv-matrix"
#ifdef __cplusplus
typedef struct CvMat CvMat;
CV_INLINE CvMat cvMat(const cv::Mat& m);
#endif
/** Matrix elements are stored row by row. Element (i, j) (i - 0-based row index, j - 0-based column /** Matrix elements are stored row by row. Element (i, j) (i - 0-based row index, j - 0-based column
index) of a matrix can be retrieved or modified using CV_MAT_ELEM macro: index) of a matrix can be retrieved or modified using CV_MAT_ELEM macro:
@ -531,6 +536,16 @@ inline CvMat::CvMat(const cv::Mat& m)
step = (int)m.step[0]; step = (int)m.step[0];
type = (type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG); type = (type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
} }
inline CvMat cvMat(const cv::Mat& m)
{
CvMat self;
CV_DbgAssert(m.dims <= 2);
self = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data);
self.step = (int)m.step[0];
self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
return self;
}
#endif #endif
@ -916,6 +931,15 @@ CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
return p; return p;
} }
#ifdef __cplusplus
template<typename _Tp>
CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt)
{
CvPoint2D32f p((float)pt.x, (float)pt.y);
return p;
}
#endif
/** converts CvPoint to CvPoint2D32f. */ /** converts CvPoint to CvPoint2D32f. */
CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
{ {

@ -255,8 +255,9 @@ void BaseTest::safe_run( int start_from )
const char* errorStr = cvErrorStr(exc.code); const char* errorStr = cvErrorStr(exc.code);
char buf[1 << 16]; char buf[1 << 16];
sprintf( buf, "OpenCV Error:\n\t%s (%s) in %s, file %s, line %d", const char* delim = exc.err.find('\n') == cv::String::npos ? "" : "\n";
errorStr, exc.err.c_str(), exc.func.size() > 0 ? sprintf( buf, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d",
errorStr, delim, exc.err.c_str(), exc.func.size() > 0 ?
exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line ); exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line );
ts->printf(TS::LOG, "%s\n", buf); ts->printf(TS::LOG, "%s\n", buf);
@ -384,7 +385,9 @@ int BadArgTest::run_test_case( int expected_code, const string& _descr )
catch(const cv::Exception& e) catch(const cv::Exception& e)
{ {
thrown = true; thrown = true;
if( e.code != expected_code ) if (e.code != expected_code &&
e.code != cv::Error::StsError && e.code != cv::Error::StsAssert // Exact error codes support will be dropped. Checks should provide proper text messages intead.
)
{ {
ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n", ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
descr, test_case_idx, e.code, expected_code); descr, test_case_idx, e.code, expected_code);
@ -471,7 +474,8 @@ string TS::str_from_code( const TS::FailureCode code )
static int tsErrorCallback( int status, const char* func_name, const char* err_msg, const char* file_name, int line, TS* ts ) static int tsErrorCallback( int status, const char* func_name, const char* err_msg, const char* file_name, int line, TS* ts )
{ {
ts->printf(TS::LOG, "OpenCV Error:\n\t%s (%s) in %s, file %s, line %d\n", cvErrorStr(status), err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line); const char* delim = std::string(err_msg).find('\n') == std::string::npos ? "" : "\n";
ts->printf(TS::LOG, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d\n", cvErrorStr(status), delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
return 0; return 0;
} }

Loading…
Cancel
Save