狗操的大作业
@@ -0,0 +1,55 @@
|
||||
import cv2 as cv
|
||||
from PIL import Image
|
||||
import pytesseract as tess
|
||||
|
||||
|
||||
def recoginse_text(image):
|
||||
"""
|
||||
步骤:
|
||||
1、灰度,二值化处理
|
||||
2、形态学操作去噪
|
||||
3、识别
|
||||
:param image:
|
||||
:return:
|
||||
"""
|
||||
|
||||
# 灰度 二值化
|
||||
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
|
||||
# 如果是白底黑字 建议 _INV
|
||||
ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY_INV| cv.THRESH_OTSU)
|
||||
|
||||
|
||||
# 形态学操作 (根据需要设置参数(1,2))
|
||||
kernel = cv.getStructuringElement(cv.MORPH_RECT,(1,2)) #去除横向细线
|
||||
morph1 = cv.morphologyEx(binary,cv.MORPH_OPEN,kernel)
|
||||
kernel = cv.getStructuringElement(cv.MORPH_RECT, (2, 1)) #去除纵向细线
|
||||
morph2 = cv.morphologyEx(morph1,cv.MORPH_OPEN,kernel)
|
||||
cv.imshow("Morph",morph2)
|
||||
|
||||
# 黑底白字取非,变为白底黑字(便于pytesseract 识别)
|
||||
cv.bitwise_not(morph2,morph2)
|
||||
textImage = Image.fromarray(morph2)
|
||||
|
||||
# 图片转文字
|
||||
text=tess.image_to_string(textImage)
|
||||
n=10 #根据不同国家车牌固定数目进行设置
|
||||
print("识别结果:")
|
||||
print(text[1:n])
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
# 读取需要识别的数字字母图片,并显示读到的原图
|
||||
src = cv.imread("cp.jpg")
|
||||
cv.imshow("src",src)
|
||||
|
||||
# 识别
|
||||
recoginse_text(src)
|
||||
|
||||
cv.waitKey(0)
|
||||
cv.destroyAllWindows()
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 172 KiB |
|
After Width: | Height: | Size: 455 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 288 KiB |
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 200 KiB |
|
After Width: | Height: | Size: 191 KiB |
|
After Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,35 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>e85e00fb-959d-4c3b-852b-f88a24227bbc</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>test.py</StartupFile>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<Name>test</Name>
|
||||
<RootNamespace>test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="test.py" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
|
||||
<!-- Uncomment the CoreCompile target to enable the Build command in
|
||||
Visual Studio and specify your pre- and post-build commands in
|
||||
the BeforeBuild and AfterBuild targets below. -->
|
||||
<!--<Target Name="CoreCompile" />-->
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
</Project>
|
||||
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 122 KiB |
|
After Width: | Height: | Size: 1.1 KiB |