如題,我在使用官方的例程時,運行到findcontour_demo時,出現了如下問題,

以下為源代碼
// ConsoleApplication6.cpp : 定義控制臺應用程式的入口點。
//
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Function header
void thresh_callback(int, void*);
/**
* @function main
*/
int main(int, char** argv)
{
/// Load source image and convert it to gray
src = imread(argv[1], 1);
/// Convert image to gray and blur it
cvtColor(src, src_gray, CV_BGR2GRAY);
blur(src_gray, src_gray, Size(3, 3));
/// Create Window
const char* source_window = "Source";
namedWindow(source_window, CV_WINDOW_AUTOSIZE);
imshow(source_window, src);
createTrackbar(" Canny thresh:", "Source", &thresh, max_thresh, thresh_callback);
thresh_callback(0, 0);
waitKey(0);
return(0);
}
/**
* @function thresh_callback
*/
void thresh_callback(int, void*)
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// Detect edges using canny
Canny(src_gray, canny_output, thresh, thresh * 2, 3);
/// Find contours
findContours(canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Draw contours
Mat drawing = Mat::zeros(canny_output.size(), CV_8UC3);
for (size_t i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point());
}
/// Show in a window
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", drawing);
}
當我對程式進行排查時,發現了是findcontours函式運算時出現了問題,運算產生的contour引數,看它內部有的部分,size明顯出了問題,有的size明顯太大。

同樣的程式,同樣的圖片,用別人的電腦跑一遍就是沒有問題的。contour里面輪廓的size大小正常,我的電腦不知道是出現了什么問題導致這樣,求大神解答。
ps:之前裝的是opencv3.0,后來因故把環境改回了2.4.7,不知道是不是這個原因的。但是現在運行其他的程式都沒有問題的啊。
uj5u.com熱心網友回復:
有人嗎??求解答啊啊啊啊啊~
uj5u.com熱心網友回復:
之前裝的是opencv3.0,后來因故把環境改回了2.4.7 再把環境改回去試試uj5u.com熱心網友回復:
崩潰的時候在彈出的對話框按相應按鈕進入除錯,按Alt+7鍵查看Call Stack即“呼叫堆疊”里面從上到下列出的對應從里層到外層的函式呼叫歷史。雙擊某一行可將游標定位到此次呼叫的源代碼或匯編指令處,看不懂時雙擊下一行,直到能看懂為止。uj5u.com熱心網友回復:
兩個版本的程式語言不同,再改代碼就很麻煩了
uj5u.com熱心網友回復:
問題的關鍵在于我知道是findcontous函式運算出了問題,導致contours陣列中有的成員的size超出了范圍,才導致后面的問題出現。我就想知道是什么原因導致findcontours函式運算出現了問題。uj5u.com熱心網友回復:
問題的關鍵在于findcontous函式是開源的。uj5u.com熱心網友回復:
https://bbs.csdn.net/topics/398340146轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/227769.html
標籤:工具平臺和程序庫
上一篇:求程式授權碼,
下一篇:cmake生成器運算式
