我曾经能够ildasm在 Visual Studio 2017 的开发人员命令提示符中运行。使用 Visual Studio 2019,ildasm不再可用:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>ildasm
'ildasm' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
是被其他东西替换了还是我的 VS 2019 安装不完整?
我有以下轮廓:
https://drive.google.com/file/d/0B45BJEUVEkjseFd3X3RITzM5S3c/edit?usp=sharing
包含以下几点(按顺序打印):
https://drive.google.com/file/d/0B45BJEUVEkjsN3NIRU5lOFBDb00/edit?usp=sharing
然而,当我计算该轮廓的面积(使用函数contourArea)时,我得到157,这对于该轮廓的大小来说太低了。我预计数量将达到数千。为什么轮廓面积计算不正确,如何修复?
以下是我用来计算图像所有轮廓面积的代码。感兴趣的轮廓是最后一个。我使用的原始图像在这里:
https://drive.google.com/file/d/0B45BJEUVEkjsbGhXM3E3UW1lZWs/edit?usp=sharing
int main(int argc, char* argv[])
{
Mat imgOriginal = imread(argv[1], 0);
if(imgOriginal.empty())
return -1;
Mat img;
resize(imgOriginal, img, Size(640, 480));
medianBlur(img, img, 11);
Canny(img, img, 25, 100);
vector< vector<Point> > contours;
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
for (int i = 0; i < contours.size(); i++)
cout << "Area " << i << ": " << contourArea(contours[i]) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
另外,我注意到轮廓中的几个点是重复的(我不确定为什么),这可能导致面积计算不正确。
如果我有一个指向父类的指针向量,并且通过实例化从父类派生的对象来初始化向量,那么看起来我不能使用基于范围的for循环,以便我将元素作为派生对象获取.这是一个简单的例子:
#include <vector>
class Parent {};
class Derived : public Parent {};
int main()
{
std::vector<Parent*> objects { new Derived(), new Derived() };
for (Derived* d : objects) { // ERROR
// Use d
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是否有一种干净的方式来做我想要的(即循环遍历派生对象)?我知道可以这样做:
for (Parent* p : objects) {
Derived* d = static_cast<Derived*>(p);
// Use d
}
Run Code Online (Sandbox Code Playgroud)
但这是C++ 11最干净的方式吗?还有什么其他选择?
该文档说“通过将深度作为数字参数给出,也可以对特定深度进行编号numbered”,这是一个toctree选项。但给它深度为0或1是不行的。还有其他想法吗?
在各种平台上测试C++程序的实用方法是什么?即使在操作系统中,我也想在不同的版本上测试它(例如,OS X 10.7,10.8,10.9等).我可以访问少数可在Windows,Linux或Mac OS X上运行的计算机,但安装了特定版本.假设我可以在该平台上编译程序.
以下是我定义的活动模式以及尝试进行模式匹配的函数:
let (|Left|) i = i = 0
let (|Top|) j = j = 0
let (|Right|) w i = i = w - 1
let (|Bottom|) h j = j = h - 1
let test w h (i, j) =
match i, j with
| (Left , Top ) -> 1
| (Left , Bottom h) -> 2
| (Right w, Top ) -> 3
| (Right w, Bottom h) -> 4
| (_ , _ ) -> …Run Code Online (Sandbox Code Playgroud)