我使用的是windows8.1,visual studio10和Opencv。 这是我的代码
#include "stdafx.h"
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv/cvaux.h>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, const char * argv[]){
// Mat数据结构用法
int Arr[256];
int x;
Mat image, A, B;
image = imread("C:/Users/chandanawin8/Desktop/len.jpg", CV_LOAD_IMAGE_COLOR);
for(int a=0; a<255;a++){
Arr[a] = 0; }
//int Arr[256] = {0}
if(!image.data){
printf("Error: Couldn't open the file.\n");
return 2;
}
cvtColor(image, A, CV_RGB2GRAY);
//creating the histogram by taking a count to an arry
for(int i=0; i<A.rows; i++){
for(int j=0; j<A.cols;j++){
x = A.at<uchar>(i,j);
Arr[x] = Arr[x]+1;
if(x<103){
A.at<uchar>(i,j) = 0; }
else if(x<219){
A.at<uchar>(i,j) = (x-103)*(220-1)/(219-103) + 1;
}
else if(x<242){
A.at<uchar>(i,j) = (x-219)*(255-220)/(242-219) +219;
}
else{
}
//pixels from 241 to 255: keep them. if want we can remove it
}
}
for(int a=0; a<255;a++){
std::cout<<"Number of "<<a<<" Value: "<<Arr[a]<<std::endl;
}
//creating the font
//cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 3,3, 0.0, 5,8);
//display the image
cvNamedWindow("Main Window", CV_WINDOW_AUTOSIZE);
imshow("Main Window", image);
cvNamedWindow("Display Window", CV_WINDOW_AUTOSIZE);
imshow("Display Window", A);
cv::waitKey(0);
image.release();
A.release();
return 0;
}
运行后出现此错误
'BreailTest2.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
The program '[3044] BreailTest2.exe: Native' has exited with code 2 (0x2).
你可以帮助我解决这个问题吗?
几天前它工作了。现在它不起作用。我有点新的opencv和visual studio
非常感谢
答案 0 :(得分:1)
问题是您的图片加载不正确。
如果您查看日志,它会告诉您应用已退出代码为2。
如果您查看代码,只需将其退出并使用2
if(!image.data){
printf("Error: Couldn't open the file.\n");
return 2;
}
因此,我会检查您是否输入了正确的文件路径,并且图像文件存在,
答案 1 :(得分:-1)
问题
image = imread("C:/Users/chandanawin8/Desktop/len.jpg", CV_LOAD_IMAGE_COLOR);
以上功能使用波纹管功能
image = cvLoadImage("C:/Users/chandanawin8/Desktop/easy.JPG",CV_LOAD_IMAGE_COLOR);