1
Q
检测图像中的边缘
A
回答
2
下面是从OpenCV的源代码的一个例子称为edge.cpp http://opencv.willowgarage.com/wiki/ 其相当多的乐趣构建和运行示例应用程序(/样品DIR)
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
using namespace cv;
using namespace std;
int edgeThresh = 1;
Mat image, gray, edge, cedge;
// define a trackbar callback
static void onTrackbar(int, void*)
{
blur(gray, edge, Size(3,3));
// Run the edge detector on grayscale
Canny(edge, edge, edgeThresh, edgeThresh*3, 3);
cedge = Scalar::all(0);
image.copyTo(cedge, edge);
imshow("Edge map", cedge);
}
static void help()
{
printf("\nThis sample demonstrates Canny edge detection\n"
"Call:\n"
" /.edge [image_name -- Default is fruits.jpg]\n\n");
}
const char* keys =
{
"{@image |fruits.jpg|input image name}"
};
int main(int argc, const char** argv)
{
help();
CommandLineParser parser(argc, argv, keys);
string filename = parser.get<string>(1);
image = imread(filename, 1);
if(image.empty())
{
printf("Cannot read image file: %s\n", filename.c_str());
help();
return -1;
}
cedge.create(image.size(), image.type());
cvtColor(image, gray, CV_BGR2GRAY);
// Create a window
namedWindow("Edge map", 1);
// create a toolbar
createTrackbar("Canny threshold", "Edge map", &edgeThresh, 100, onTrackbar);
// Show the image
onTrackbar(0, 0);
// Wait for a key stroke; the same function arranges events processing
waitKey(0);
return 0;
}
,如果你想建立它分开您OpenCV的构建,你可以使用这个脚本 (一个版本是C样品目录下提供的 - 我修改了它编译额外的库)
#!/bin/sh
if [ $# -gt 0 ] ; then
base=`basename $1 .c`
echo "compiling $base"
gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
else
for i in *.c; do
echo "compiling $i"
gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
done
for i in *.cpp; do
echo "compiling $i"
g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config -- libs opencv` -lpthread -D_REENTRANT;
done
fi
相关问题
- 1. 图像边缘检测
- 2. C++中的图像边缘检测
- 3. 图像处理中的边缘检测
- 4. 检测图像中的U形边缘
- 5. 如何测量边缘检测图像边缘的长度?
- 6. 从边缘检测中分割图像
- 7. 图像地图边缘检测
- 8. Canny边缘检测器检测到所述图像的边界
- 9. 图像边缘检测和平滑?
- 10. Javascript滚动图像边缘检测
- 11. 图像分割与边缘检测
- 12. 检测图中的相互边缘
- 13. OpenCV中的边缘检测
- 14. C#中的边缘检测
- 15. 矢量图像的图像比较(基于边缘检测)?
- 16. SQLITE边缘检测
- 17. VHDL边缘检测
- 18. Canny边缘检测
- 19. qTip2边缘检测
- 20. Python大图像边缘检测使用Scikit图像和GDAL
- 21. 使用OpenCV在android中检测图像的边缘?
- 22. 检测彩色图像中的水平圆形边缘
- 23. 如何检测图像中只有红色物体的边缘
- 24. 使用Python检测图像中激光/光线的边缘
- 25. 如何检测Java中图像的边缘(透明背景)?
- 26. 如何在Android中检测图像(硬币)的边缘?
- 27. opencv:操纵边缘检测像素
- 28. 使用CIImage“内部”(像边缘)检测?
- 29. 图像检索 - 边缘直方图
- 30. 图像边缘/形状检测在OpenCV中
有几个很好的边缘检测算法你可以尝试http://en.wikipedia.org/wiki/Edge_detection Sobel,Prewitt – tempidope