我正在开发指纹匹配项目,我是使用openCV库的新手,
这是一个显示直方图的简单代码,它存在于openCV
的示例文件夹中int main(int, char** argv)
{
Mat src, dst;
/// Load image
src = cv::imread("contour.jpg");
cv::waitKey(5000);
//waitKey(0);
if (!src.data)
{
return -1;
}
/// Separate the image in 3 places ( B, G and R )
..
vector<Mat> bgr_planes;
split(src, bgr_planes);
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;
/// Compute the histograms:
calcHist(&bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate);
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate);
calcHist(&bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate);
// Draw the histograms for B, G and R
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound((double)hist_w / histSize);
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar(0, 0, 0));
/// Normalize the result to [ 0, histImage.rows ]
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());
/// Draw for each channel
for (int i = 1; i < histSize; i++)
{
line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(b_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(b_hist.at<float>(i))),
Scalar(255, 0, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(g_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(g_hist.at<float>(i))),
Scalar(0, 255, 0), 2, 8, 0);
line(histImage, Point(bin_w*(i - 1), hist_h - cvRound(r_hist.at<float>(i - 1))),
Point(bin_w*(i), hist_h - cvRound(r_hist.at<float>(i))),
Scalar(0, 0, 255), 2, 8, 0);
}
/// Display
namedWindow("calcHist Demo", WINDOW_AUTOSIZE);
imshow("calcHist Demo", histImage);
waitKey(0);
return 0;
}
我将文件contour.jpg保存在与cpp文件相同的文件夹中。
我尝试了很多,但它显示以下警告,并且不显示输出窗口。
我也尝试更改命令参数变量,仍然没有输出。
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Users\jaythegenius48\Documents\Visual Studio 2013\Projects\ConsoleApplication5\Debug\ConsoleApplication5.exe'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_core249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_highgui249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\opencv\build\x86\vc12\bin\opencv_imgproc249.dll'. Cannot find or open the PDB file.
'ConsoleApplication5.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Symbols loaded.
The program '[916] ConsoleApplication5.exe' has exited with code -1 (0xffffffff).
非常感谢您的帮助,谢谢
编辑:好的,这是我自己的问题的解决方案:
1)我不知道我做了什么,但我开始了一个新项目。
2)右键单击您的项目,然后 - > gt;属性。
3)取决于你的opencv目录(我建议&#34; C:\ opencv&#34;对于windows),
在包含目录和库目录中进行以下更改(选择相应的
文件夹)。我建议使用x86文件夹,即使你有64位架构。
4)然后关注三张图片:
最后:
在该文本空白区域中添加以下文件。
注意:根据你的opencv文件名的版本会有变化,我的是2.4.9所以它以249结束,对于那些使用2.4.3的人来说是243。
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
我希望这会有所帮助。令人沮丧但努力工作得到回报。
感谢其他成员回答我的问题。
答案 0 :(得分:2)
处理文件(在我看来)是难事之一。也就是说放在哪里。
尝试将图像放在与可执行文件相同的目录中,而不是源文件中。