Merge pull request #16046 from alalek:issue_15990

* core: disable invalid constructors in C API by default

- C API objects will lose their default initializers through constructors

* samples: stop using of C API
This commit is contained in:
Alexander Alekhin
2019-12-05 14:48:18 +03:00
committed by GitHub
parent 986c5084a4
commit f21bde4d9f
4 changed files with 17 additions and 16 deletions
@@ -19,21 +19,21 @@ static void help( char* progName)
<< progName << " [image-name Default: ../data/lena.jpg]" << endl << endl;
}
//! [start]
// comment out the define to use only the latest C++ API
#define DEMO_MIXED_API_USE
//#define USE_LEGACY_C_API 1 // not working with modern OpenCV
#ifdef DEMO_MIXED_API_USE
# include <opencv2/highgui/highgui_c.h>
# include <opencv2/imgcodecs/imgcodecs_c.h>
#endif
//! [start]
int main( int argc, char** argv )
{
help(argv[0]);
const char* imagename = argc > 1 ? argv[1] : "../data/lena.jpg";
#ifdef DEMO_MIXED_API_USE
#ifdef USE_LEGACY_C_API
Ptr<IplImage> IplI(cvLoadImage(imagename)); // Ptr<T> is a safe ref-counting pointer class
if(!IplI)
{
@@ -101,7 +101,7 @@ int main( int argc, char** argv )
const double brightness_gain = 0;
const double contrast_gain = 1.7;
#ifdef DEMO_MIXED_API_USE
#ifdef USE_LEGACY_C_API
// To pass the new matrices to the functions that only work with IplImage or CvMat do:
// step 1) Convert the headers (tip: data will not be copied).
// step 2) call the function (tip: to pass a pointer do not forget unary "&" to form pointers)
@@ -133,7 +133,7 @@ int main( int argc, char** argv )
namedWindow("image with grain", WINDOW_AUTOSIZE); // use this to create images
#ifdef DEMO_MIXED_API_USE
#ifdef USE_LEGACY_C_API
// this is to demonstrate that I and IplI really share the data - the result of the above
// processing is stored in I and thus in IplI too.
cvShowImage("image with grain", IplI);
@@ -131,8 +131,8 @@ int main(int,char**)
{
//! [C-API conversion]
Mat img = imread("image.jpg");
IplImage img1 = img;
CvMat m = img;
IplImage img1 = cvIplImage(img);
CvMat m = cvMat(img);
//! [C-API conversion]
CV_UNUSED(img1);
CV_UNUSED(m);