VC++ 錯誤56 error C2665: std::vector《edge,std::allocator _Ty》 10 個重載中沒有一個可以轉換所有參數類型

錯誤    56    error C2665: “std::vector<edge,std::allocator<_Ty>>::vector”: 10 個重載中沒有一個可以轉換所有參數類型    f:\test\堆\opencv_mfc\opencv_mfc\opencv_mfcview.cpp    3432    1    OpenCV_MFC
  

錯誤    57    IntelliSense:  沒有與參數列表匹配的構造函數 "std::vector<_Ty, _Alloc>::vector [其中 _Ty=edge, _Alloc=std::allocator<edge>]" 實例
            參數類型爲:  (int, int)    f:\test\堆\OpenCV_MFC\OpenCV_MFC\OpenCV_MFCView.cpp    3432    47    OpenCV_MFC

struct edge{
	//float w;
	double weight_v[8] ;
	int width = 0, high = 0, value = 0;
};

void COpenCV_MFCView::On_graph_cut_test()//以兩個閾值把圖像分割爲三個區域
{
	COpenCV_MFCDoc* pDoc = GetDocument();
	CDC* pDC = GetDC();
	int i, j, ii;
	Mat srcImg = imread(pDoc->filePath, CV_LOAD_IMAGE_COLOR);//讀取圖像
	cvtColor(srcImg, srcImg, CV_BGR2GRAY);//灰度化
	MatShowImg(pDC, srcImg, srcImg.cols, 0);//顯示灰度圖
	int width = srcImg.size().width;
	int height = srcImg.size().height;

	vector<std::vector<edge> > graph_img(height, vector<edge>(width, 0));//點的結構圖矩陣,積分圖
	vector<edge> model_line(width, 0);
}

vector<std::vector<edge> > graph_img(height, vector<edge>(width, 0));

vector<edge> model_line(width, 0);

這裏有明顯的初始化錯誤,結構體爲edge,不能用0初始化,(例如:普通案例vector<int> model_line(width, 0);  其中int可以初始化爲0)。 而結構體爲edge只能先實例化一個edge對象來把vector初始化,則可以解決。

edge model_point;
ector<std::vector<edge> > graph_img(height, vector<edge>(width, model_point));

vector<edge> model_line(width, model_point);

struct edge{
	//float w;
	double weight_v[8];
	int width = 0, high = 0, value = 0;
};

void COpenCV_MFCView::On_graph_cut_test()//以兩個閾值把圖像分割爲三個區域
{
	COpenCV_MFCDoc* pDoc = GetDocument();
	CDC* pDC = GetDC();
	int i, j, ii;
	Mat srcImg = imread(pDoc->filePath, CV_LOAD_IMAGE_COLOR);//讀取圖像
	cvtColor(srcImg, srcImg, CV_BGR2GRAY);//灰度化
	MatShowImg(pDC, srcImg, srcImg.cols, 0);//顯示灰度圖
	int width = srcImg.size().width;
	int height = srcImg.size().height;
	edge model_point;
	model_point.weight_v[8] = { 0 };
	model_point.width = 0;
	model_point.high = 0;
	model_point.value = 0;

	vector<std::vector<edge> > graph_img(height, vector<edge>(width, 0));//點的結構圖矩陣,積分圖
	vector<edge> model_line(width, model_point);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章