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