- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在一个使用形态学函数的 opencv 项目中工作。现在我正在尝试在 gpu 支持下进行。
当我使用 opencv 3.0 和 cuda 7.5 支持编译我的程序时,它接受除了 morphologyEx 之外的大部分函数(例如 cuda::threshold、cuda::cvtcolor 等)。请注意,morphologyex 在 opencv 2.4.9 中称为 gpu::morphologyEx。
如何在 OpenCV 3.0 或 3.1 中使用此功能?如果不支持,是否有替代此功能的方法?
实际上我正在使用这个函数在非均匀光照下进行背景检测。我正在将代码添加到问题中。请建议我如何替换 morphologyEx 函数。
#include <opencv2\opencv.hpp>
using namespace cv;
int main()
{
// Step 1: Read Image
Mat1b img = imread("path_to_image", IMREAD_GRAYSCALE);
// Step 2: Use Morphological Opening to Estimate the Background
Mat kernel = getStructuringElement(MORPH_ELLIPSE, Size(15,15));
Mat1b background;
morphologyEx(img, background, MORPH_OPEN, kernel);
// Step 3: Subtract the Background Image from the Original Image
Mat1b img2;
absdiff(img, background, img2);
// Step 4: Increase the Image Contrast
// Don't needed it here, the equivalent would be cv::equalizeHist
// Step 5(1): Threshold the Image
Mat1b bw;
threshold(img2, bw, 50, 255, THRESH_BINARY);
// Step 6: Identify Objects in the Image
vector<vector<Point>> contours;
findContours(bw.clone(), contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
for(int i=0; i<contours.size(); ++i)
{
// Step 5(2): bwareaopen
if(contours[i].size() > 50)
{
// Step 7: Examine One Object
Mat1b object(bw.size(), uchar(0));
drawContours(object, contours, i, Scalar(255), CV_FILLED);
imshow("Single Object", object);
waitKey();
}
}
return 0;
}
============================================= ===========================感谢@Roy Falk看了有值(value)的评论和文档,感觉morphologyEX的功能
morphologyEx(img, background, MORPH_OPEN, kernel);
可以替换为
cv::Ptr<cv::cuda::Filter>morph = cuda::createMorphologyFilter(MORPH_OPEN, out.type(), kernel);
morph->apply(out, bc);
如果我说错了,欢迎指出
最佳答案
如上面的评论所述,形态学不在 3.1 API 中。
我猜您需要按照 2.4 documentation 中的说明映射调用在 3.1 中完成的方式.
具体来说,morphologyex 具有以下参数:
...等等
换句话说,2.4是一口气做了操作(morphologyex)。在 3.1 中,您首先使用 createFooFilter 创建过滤器,然后调用应用过滤器。
这不是一个明确的答案,更多的是一个建议,但不能真正在评论中写下所有这些。祝你好运。
============================================= ==================
编辑:尝试查看 https://github.com/Itseez/opencv/blob/master/samples/gpu/morphology.cpp .它展示了如何使用 cuda::createMorphologyFilter
关于opencv - 在 opencv 3 中使用 cuda::morphologyex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35321289/
我正在编写一个 c++ 代码,用于比较使用 CPU 和 GPU 版本的 opencv morphologyEx 方法的性能。这是我的代码: #include #include #include
去除验证码背景后。 图像保留数字和噪声。 噪声线都是一种颜色:RGB(127,127,127) 然后使用形态学方法。 kernel = cv2.getStructuringElement(cv
我想用白色边框填充我的灰度图像,以便在 opencv(在 Python 中)中进行形态关闭。文档并没有真正说明函数需要什么。我一直在尝试以下两个示例但无济于事: smooth_mask = cv2.m
我有以下图像,其中包含无人机捕获的汽车和空 parking 位。我想检测空的公园空间并绘制一个看起来像预期图像的框。 这是我的代码: import cv2 import numpy as np fro
如何使用新的emgu版本打开和关闭图像处理? 我发现了这个: www.stackoverflow.com/questions/11567350/opening-and-closing-using-op
我在一个使用形态学函数的 opencv 项目中工作。现在我正在尝试在 gpu 支持下进行。 当我使用 opencv 3.0 和 cuda 7.5 支持编译我的程序时,它接受除了 morphologyE
我需要在我的图像处理项目中调用 cvMorphologyEx,我使用这一行来完成。 cvMorphologyEx(src1,dest1,NULL,NULL,CV_MOP_OPEN); 编译正常,但运行
我是一名优秀的程序员,十分优秀!