qq_36264158
2018-01-01 06:39
采纳率: 100%
浏览 2.7k

CSDN上找了一段基于opencv车牌检测的代码,用他的图片没问题,随便换张图片debug时有问题

代码如下:
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;

define PI 3.1415926

#include "hough_find_line.cpp"

int verifySizes(Rect m,Mat input);
int main()
{
Mat img_gray;
Mat input=imread("13.jpg");
cvtColor(input, img_gray, CV_BGR2GRAY);
blur(img_gray, img_gray, Size(5,5));

//**************************************************第一部分——车牌定位***************************//
// 突出垂直边缘
Mat img_sobel;
Sobel(img_gray, img_sobel, CV_8U, 1, 0, 3, 1, 0, BORDER_DEFAULT);

// 阈值化处理,形态学处理
Mat img_threshold;
threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_OTSU+CV_THRESH_BINARY);

Mat gauss_diff,threshAgain_diff;
GaussianBlur(img_threshold,gauss_diff,Size(9,9),3.0);//对二值图像高斯滤波

threshold(gauss_diff,threshAgain_diff,29,255,CV_THRESH_BINARY);//再次阈值化取二值

Mat mor_close;
Mat mor_open;
Mat element5(8,8,CV_8U,Scalar(1));
Mat element = getStructuringElement(MORPH_RECT, Size(24,4) );
morphologyEx(threshAgain_diff, mor_close, CV_MOP_CLOSE, element);//闭运算

morphologyEx(mor_close,mor_open,MORPH_OPEN,element5);//开运算

// 利用findContours函数寻找车牌可能的轮廓
vector< vector< Point> > contours;
findContours(mor_open,
contours, // 轮廓的数组
CV_RETR_EXTERNAL, // 获取外轮廓
CV_CHAIN_APPROX_NONE); // 获取每个轮廓的每个像素
// 排除非车牌的可能轮廓
vector >::iterator itc= contours.begin();
vector rects;

Rect mr= boundingRect(Mat(*itc));

while (itc!=contours.end())
{
// minAreaRect函数计算最小包围旋转矩形
Rect mr= boundingRect(Mat(*itc));
if( !verifySizes(mr,img_gray)){
itc= contours.erase(itc);
}else{
++itc;
rects.push_back(mr);
}
}
// 画出轮廓
cv::Mat result;
input.copyTo(result);
cv::drawContours(result,contours,
-1, // draw all contours
cv::Scalar(0,0,255), // in blue
1); // with a thickness of 1

//提取出车牌
Mat imgroi;
vector::iterator it=rects.begin();
imgroi = input(*it); //感觉这里有问题,这句之前debug没问题,把这句加上就有问题了

这是我在CSDN上找的一段程序,用他本来的图片debug是没问题的,但是随便换一张图片就有问题了。下面两张是错误提示,第二张是第一张点了忽略后出现的。
![![图片说明](https://img-ask.csdn.net/upload/201801/01/1514787567_795197.jpg)图片说明](https://img-ask.csdn.net/upload/201801/01/1514787544_63640.jpg)
下面是更换图片后debug时output窗口的输出

'anpr2.exe': Loaded 'F:\迅雷下载\anpr2\Debug\anpr2.exe', Symbols loaded.

'anpr2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'anpr2.exe': Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'anpr2.exe': Loaded 'E:\opencv\opencv\build\x86\vc10\bin\opencv_highgui2410d.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'E:\opencv\opencv\build\x86\vc10\bin\opencv_imgproc2410d.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'E:\opencv\opencv\build\x86\vc10\bin\opencv_core2410d.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\win32u.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\gdi32full.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\combase.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\ucrtbase.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msvcp_win.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.14393.447_none_5507ded2cb4f7f4c\comctl32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msvfw32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\avifil32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\avicap32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msacm32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\windows.storage.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\powrprof.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\winmmbase.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\SHCore.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\profapi.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\SogouTSF.ime', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\msimg32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\SogouPY.ime', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\ntmarta.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'E:\SogouInput\8.7.0.1682\Resource.dll', Binary was not built with debug information.
'anpr2.exe': Loaded 'E:\SogouInput\Components\PicFace\1.1.0.1781\PicFace.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\comdlg32.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x103c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1278) has exited with code 0 (0x0).
'anpr2.exe': Loaded 'E:\SogouInput\Components\SogouFlash\1.0.0.203\sogouflashdll.dll', Cannot find or open the PDB file
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\Wldap32.dll', Cannot find or open the PDB file
'anpr2.exe': Unloaded 'C:\Windows\SysWOW64\SogouTSF.ime'
'anpr2.exe': Loaded 'C:\Windows\SysWOW64\SogouTSF.ime', Cannot find or open the PDB file
'anpr2.exe': Unloaded 'C:\Windows\SysWOW64\SogouTSF.ime'
Microsoft Visual Studio C Runtime Library has detected a fatal error in anpr2.exe.

一直找不到毛病,恳请大佬解答,给出解决方法,谢谢了

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

8条回答 默认 最新

  • blownewbee 2018-01-01 07:27
    已采纳

    看下图片的格式、二值化以后的清晰度、倾斜和噪声是否太大。等等。

    点赞 打赏 评论
  • qq_36264158 2018-01-01 06:41

    图片说明这是错误提示

    点赞 打赏 评论
  • 古天九等一缕 2018-01-02 01:16

    你好,换成release版本并配置release版本的动态库试一试。

    点赞 打赏 评论
  • qq_36264158 2018-01-02 06:18

    本人觉得应该是代码bug,但我又对c++了解不多,真心希望有大牛帮我看看,如果觉得网站交流不方便可以联系我qq2515349881.或者您留下联系方式,我联系您,感激不尽。

    点赞 打赏 评论
  • fengguixiang1 2018-01-03 07:28

    换一个图片试试,可能是图片格式有问题,或者是代码中有限制图片样式

    点赞 打赏 评论
  • 逐无尽之涯 2018-01-04 07:38

    我也发生过这种问题,我后来想的是因为你用的图片不符合程序里的要求,也就是你的图片不具有的一些特征,但是程序里要进行分析,处理,希望你能充分理解你所使用的程序。

    点赞 打赏 评论
  • angreens 2018-01-06 03:44

    估计你迭代器使用有问题,你检查下自己代码。
    使用迭代器读取vector中的每一个元素:
    vector ivec(10,1);
    for(vector::iterator iter=ivec.begin();iter!=ivec.end();++iter)
    {
    *iter=2; //使用 * 访问迭代器所指向的元素
    }

    点赞 打赏 评论
  • 猿来巡山 2018-01-13 08:31

    迭代器 使用 越界之类的原因吧

    点赞 打赏 评论

相关推荐 更多相似问题