【发布时间】:2016-02-13 11:50:56
【问题描述】:
我在一个使用morphologyex 函数的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 看了很有价值的cmets和文档,感觉morphologyEX的功能
morphologyEx(img, background, MORPH_OPEN, kernel);
可以替换为
cv::Ptr<cv::cuda::Filter>morph = cuda::createMorphologyFilter(MORPH_OPEN, out.type(), kernel);
morph->apply(out, bc);
如果我错了,尽管说
【问题讨论】:
-
这似乎是一个更适合谷歌的问题。我在这里假设是善意的,openCSV+cuda7.5 不知何故使这一点复杂化,但你应该花更多的时间来解释为什么这在谷歌上很难找到。设置带有错误消息和架构的场景将大大有助于产生善意并吸引人们关注这个问题。例如:我正在尝试在运行的遗留嵌入式系统上运行 OpenCSV……它仅适用于 Cuda7.5(过时)并且代码示例不起作用,因为……我认为我需要一个特定的头文件不在那里...
-
现在问题已编辑,谢谢
-
morphologyex 似乎从 docs.opencv.org/3.0-beta/modules/cudafilters/doc/filtering.html 中消失了。你能发布确切的 morpholyex 调用吗?