我試過了2個圖像的findContours。其實,它們是一個。一個是彩色圖像(JPG),另一種是從由MS塗料顏色之一創建(出口到單色圖像 - BMP):findContours爲「相同」圖像提供了不同的結果
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace cv;
using namespace std;
char* org_file = "expmap_1.bmp"; //"expmap.jpg"; // "pic1.png";
int main(int argc, char** argv)
{
Mat src;
// the first command line parameter must be file name of binary
// (black-n-white) image
src = imread(org_file, 0); // both are read in binary form
Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
// src = src > 1;
namedWindow("Source", 1);
imshow("Source", src);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(src, contours, hierarchy,
CV_RETR_LIST , CV_CHAIN_APPROX_SIMPLE);
// iterate through all the top-level contours,
// draw each connected component with its own random color
cout << contours.size() << endl;
int idx = 0;
for(; idx >= 0; idx = hierarchy[idx][0])
{
// Scalar color(rand()&255, rand()&255, rand()&255);
//Scalar color(255,255,255);
drawContours(dst, contours, idx, RGB(0,0,255), 1, 8, hierarchy);
}
namedWindow("Components", 1);
imshow("Components", dst);
waitKey(0);
}
命令作品與單色圖像給出正確的結果,但另一個只返回1個輪廓,即圖像幀。
2例有什麼區別嗎?
照片,我用: **顏色之一: http://imageshack.us/photo/my-images/440/picture73q.jpg/
**位圖中: http://imageshack.us/photo/my-images/16/picture73l.png/
你可以看到,他們是一樣的,只是類型不同(彩色/黑白)我也在OpenCV代碼中進行了轉換。
我來到我身邊還停留在這個
PS:任何人都可以幫助我,以顯示上傳圖片就在崗位?這樣助手就不必點擊查看
你能提供這些圖片嗎? – dom 2012-03-12 16:21:16
我不知道如何在這裏上傳圖片。基本上,兩個圖像是相同的,一個室內圖像有一些障礙。一個是彩色JPG,另一個是彩色 – 2012-03-13 07:12:55
創建的單色,您可以在imageshack.us上傳圖像並在此處提供鏈接。很簡單。 – 2012-03-13 13:53:10