2012-12-01 126 views
1

我有一個房間的圖像。我想檢測圖像中的邊緣 - 即在天花板周圍繪製線條或圍繞窗口繪製線條。這個問題有多困難 - 有沒有這樣的庫?檢測圖像中的邊緣

這是爲iOS應用程序,但我的問題是平臺/語言無關。

+1

有幾個很好的邊緣檢測算法你可以嘗試http://en.wikipedia.org/wiki/Edge_detection Sobel,Prewitt – tempidope

回答

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