std::string 在 opencv 中被视为 cv::String

Eas*_*322 -1 c++ opencv namespaces visual-c++ visual-studio-2019

我在 Visual Studio 19 中有一个 C++20 控制台项目,具有发布配置和 /MT 标志。我在项目中明确指定类型的命名空间。当我创建时

std::string Foo, 
Run Code Online (Sandbox Code Playgroud)

它创建 std::string 类型。到目前为止,一切都很好。然而,当我创建

std::vector <std::string> Bar,
Run Code Online (Sandbox Code Playgroud)

相反,它创建了一种std::vector<cv::String>类型,这会导致不良后果。cv 命名空间来自 OpenCV4。不仅来自不同的命名空间,类型本身也以大写“S”开头。我的项目中的任何地方都没有任何“使用命名空间”或任何其他“使用”。

有任何想法吗?

我尝试在该行之前使用“using namespace std”,以防万一,但是,正如预期的那样,它不起作用。

我已经预料到了

std::vector <std::string> Bar 
Run Code Online (Sandbox Code Playgroud)

创建一个

std::vector <std::string>
Run Code Online (Sandbox Code Playgroud)

类型,我做错了什么?

Ted*_*gmo 5

cv::Stringstd::string实际上是同一件事。

opencv2/core/cvstd.hpp

namespace cv {
typedef std::string String;
}
Run Code Online (Sandbox Code Playgroud)

您可以通过以下方式验证:

#include <type_traits>

static_assert(std::is_same_v<std::string, cv::String>, "");
Run Code Online (Sandbox Code Playgroud)