opencv 4.x API与以前的版本有何不同? [英] How opencv 4.x API is different from previous version?

查看:829
本文介绍了opencv 4.x API与以前的版本有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到opencv 4已发布,并且区别在于API已更改为与c ++ 11兼容.

I noted that opencv 4 is released and one difference is that API changed to be c++11 compliant.

这到底意味着什么?

我应该如何更改我的代码以使其与此版本兼容?

How should I change my codes to be compatible with this version?

推荐答案

我认为最不同的是,OpenCV 4.0使用了更多的C ++ 11功能.现在,cv::String == std::stringcv::Ptrstd::shared_ptr之上的薄包装.

I think the most different is, the OpenCV 4.0 use more C++11 features. Now cv::String == std::string and cv::Ptr is a thin wrapper on top of std::shared_ptr.

Opencv 4.0删除文件夹include/opencv,仅保留include/opencv2. OpenCV 1.x中的许多C API已被删除.受影响的模块是objdetect, photo, video, videoio, imgcodecs, calib3d.不建议使用旧的宏定义或未命名的枚举,请使用insted命名的枚举.

The Opencv 4.0 remove folder include/opencv and only keep include/opencv2. A lot of C API from OpenCV 1.x has been removed. The affected modules are objdetect, photo, video, videoio, imgcodecs, calib3d. The old macro defination or unnamed enum is not suggested, use named enum insted.

//! include/opencv2/imgcodes.hpp
namespace cv
{

//! @addtogroup imgcodecs
//! @{

//! Imread flags
enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
       IMREAD_GRAYSCALE            = 0,  //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
       IMREAD_COLOR                = 1,  //!< If set, always convert image to the 3 channel BGR color image.
       IMREAD_ANYDEPTH             = 2,  //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
       IMREAD_ANYCOLOR             = 4,  //!< If set, the image is read in any possible color format.
       IMREAD_LOAD_GDAL            = 8,  //!< If set, use the gdal driver for loading the image.
       IMREAD_REDUCED_GRAYSCALE_2  = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
       IMREAD_REDUCED_COLOR_2      = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
       IMREAD_REDUCED_GRAYSCALE_4  = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
       IMREAD_REDUCED_COLOR_4      = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
       IMREAD_REDUCED_GRAYSCALE_8  = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
       IMREAD_REDUCED_COLOR_8      = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
       IMREAD_IGNORE_ORIENTATION   = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
     };

    // ...
}

例如,当读取图像时,应该是这样的:

Such as, when read image, it should be something like this:

cv::Mat img = cv::imread("test.png", cv::IMREAD_COLOR);


除新功能外,大多数C ++ API保持不变.我发现最大的区别是cv2.findContours(在Python OpenCV中):


Except the new featues, the most C++ APIs keep the same. While the biggest different I found is cv2.findContours (in Python OpenCV):

在OpenCV 3.4中:

In OpenCV 3.4:

findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy

在OpenCV 4.0中:

In OpenCV 4.0:

findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy

使用2.x,3.x,4.x的另一种方法是:

An alternative to work with 2.x 、3.x、4.x is:

cnts, hiers = cv2.findContours(...)[-2:]


一些链接:


Some links:

  1. OpenCV版本
  2. OpenCV ChangeLog
  3. OpenCV简介
  4. OpenCV文档
  5. 如何使用`cv2.findContours `在不同的OpenCV版本中?
  6. Stackoverflow上的OpenCV
  1. OpenCV Release
  2. OpenCV ChangeLog
  3. OpenCV Introduction
  4. OpenCV Documentation
  5. How to use `cv2.findContours` in different OpenCV versions?
  6. OpenCV on Stackoverflow

这篇关于opencv 4.x API与以前的版本有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆