[問題] Open CV取面積

看板C_and_CPP (C/C++)作者 (HAPPY123)時間11年前 (2015/04/09 19:26), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) OpenCV 問題(Question): 我要計算一塊黑色區域的面積(已經二值化過),但是我跑到最後一段的時候卻會發生錯誤 ,請各位高手幫忙看看哪裡錯誤,感謝 程式碼(Code):(請善用置底文網頁, 記得排版) using namespace cv; using namespace std; double area; Mat image=imread("binary1.Jpg",0); vector<vector <cv::Point>> contours; findContours(image,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE); Mat result(image.size(),CV_8U,Scalar(255)); drawContours(result,contours,-1,Scalar(0),2); imshow("resultImage",result); area=contourArea(contours); -- Sent from my Android -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.138.234.34 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1428578790.A.4A6.html

04/09 20:10, , 1F
不知道是哪行出問題嗎? 不是可以測試?
04/09 20:10, 1F

04/09 20:14, , 2F
有跑過了,最後area=那段會錯誤
04/09 20:14, 2F

04/09 21:27, , 3F
contourArea傳入的東西不對
04/09 21:27, 3F

04/09 21:28, , 4F
應該要傳入 vector<Point>
04/09 21:28, 4F

04/09 21:31, , 5F
contours一個row 就可以算一個contour的面積了
04/09 21:31, 5F

04/09 21:37, , 6F
Contourarea(contour.at(i));
04/09 21:37, 6F

04/13 16:05, , 7F
感謝大家,已經解決了
04/13 16:05, 7F
文章代碼(AID): #1L9c7cIc (C_and_CPP)
文章代碼(AID): #1L9c7cIc (C_and_CPP)