qq_36264158 2018-01-01 06:39 采纳率: 100%
浏览 2686
已采纳

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条回答 默认 最新

  • threenewbee 2018-01-01 07:27
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)
  • ¥15 如何解决MIPS计算是否溢出
  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决