@ -0,0 +1,3 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="PLAIN" />
|
||||
<option name="myDocStringFormat" value="Plain" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,41 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredPackages">
|
||||
<value>
|
||||
<list size="21">
|
||||
<item index="0" class="java.lang.String" itemvalue="torchvision" />
|
||||
<item index="1" class="java.lang.String" itemvalue="Flask" />
|
||||
<item index="2" class="java.lang.String" itemvalue="tqdm" />
|
||||
<item index="3" class="java.lang.String" itemvalue="protobuf" />
|
||||
<item index="4" class="java.lang.String" itemvalue="tensorflow" />
|
||||
<item index="5" class="java.lang.String" itemvalue="Flask-Cors" />
|
||||
<item index="6" class="java.lang.String" itemvalue="faiss-cpu" />
|
||||
<item index="7" class="java.lang.String" itemvalue="numpy" />
|
||||
<item index="8" class="java.lang.String" itemvalue="requests" />
|
||||
<item index="9" class="java.lang.String" itemvalue="opencv-python-headless" />
|
||||
<item index="10" class="java.lang.String" itemvalue="Pillow" />
|
||||
<item index="11" class="java.lang.String" itemvalue="tensorboard" />
|
||||
<item index="12" class="java.lang.String" itemvalue="ipython" />
|
||||
<item index="13" class="java.lang.String" itemvalue="albumentations" />
|
||||
<item index="14" class="java.lang.String" itemvalue="scipy" />
|
||||
<item index="15" class="java.lang.String" itemvalue="h5py" />
|
||||
<item index="16" class="java.lang.String" itemvalue="matplotlib" />
|
||||
<item index="17" class="java.lang.String" itemvalue="opencv_contrib_python" />
|
||||
<item index="18" class="java.lang.String" itemvalue="packaging" />
|
||||
<item index="19" class="java.lang.String" itemvalue="terminaltables" />
|
||||
<item index="20" class="java.lang.String" itemvalue="gradio" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="pandas" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Imag_Enhanc_License_recog-main.iml" filepath="$PROJECT_DIR$/.idea/Imag_Enhanc_License_recog-main.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,37 @@
|
||||
#coding:utf-8
|
||||
from ultralytics import YOLO
|
||||
import cv2
|
||||
|
||||
# 所需加载的模型目录
|
||||
path = 'models/best.pt'
|
||||
# 需要检测的图片地址
|
||||
img_path = "TestFiles/aa.jpg"
|
||||
|
||||
# 加载预训练模型
|
||||
model = YOLO(path, task='detect')
|
||||
|
||||
# 检测图片
|
||||
results = model(img_path)
|
||||
|
||||
# 读取原始图片
|
||||
img = cv2.imread(img_path)
|
||||
|
||||
# 遍历所有检测结果
|
||||
for result in results:
|
||||
# 获取检测框的坐标
|
||||
for i, box in enumerate(result.boxes):
|
||||
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
||||
# 裁剪检测框内的图像
|
||||
cropped_img = img[y1:y2, x1:x2]
|
||||
# 显示裁剪后的图像
|
||||
cv2.imshow("Cropped Image", cropped_img)
|
||||
cv2.waitKey(0)
|
||||
# 构建保存路径
|
||||
save_path = f"TestFiles/cropped_license_plate_{i}.jpg"
|
||||
# 保存裁剪后的图像
|
||||
cv2.imwrite(save_path, cropped_img)
|
||||
|
||||
# 显示原始图像上的检测结果
|
||||
res = results[0].plot()
|
||||
cv2.imshow("YOLOv5 Detection", res)
|
||||
cv2.waitKey(0)
|
@ -0,0 +1,37 @@
|
||||
# ImagEnhanc-Licenserecog_cxy_zhw
|
||||
|
||||
#### 介绍
|
||||
数字图像期末作业《图像基本处理和车牌定位识别系统》——曹芯依、张昊玮
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
@ -0,0 +1,20 @@
|
||||
1.创建虚拟环境并安装相关依赖
|
||||
#创建虚拟环境
|
||||
conda create -n pytorch_1.8 python=3.8
|
||||
#进入虚拟环境
|
||||
conda activate pytorch_1.8
|
||||
|
||||
# 安装项目依赖包
|
||||
python -m pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
python -m pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple/
|
||||
pip install gradio==3.47.1
|
||||
(缺少哪个包就类似方法安装哪个包即可)
|
||||
|
||||
2.运行项目脚本
|
||||
# 2.1进入到项目虚拟环境
|
||||
conda activate pytorch_1.8
|
||||
# 2.2 cd 到项目根目录
|
||||
D:
|
||||
cd Imag_Enhanc_License_recog-main/
|
||||
# 2.3 运行项目
|
||||
python demo_ui_main.py
|
After Width: | Height: | Size: 72 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 83 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 222 KiB |
@ -0,0 +1,85 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
'''
|
||||
基于Opencv图像处理的车牌定位和分割
|
||||
'''
|
||||
def car_plate_recognize(car):
|
||||
"""=========================== 1. 定位车牌(车牌检测)==========================="""
|
||||
# 蓝色、黄色和绿色所对应的色彩空间
|
||||
lower_blue = np.array([100, 110, 110])
|
||||
upper_blue = np.array([130, 255, 255])
|
||||
lower_yellow = np.array([15, 55, 55])
|
||||
upper_yellow = np.array([50, 255, 255])
|
||||
lower_green = np.array([35, 100, 100])
|
||||
upper_green = np.array([85, 255, 255])
|
||||
|
||||
hsv = cv2.cvtColor(car, cv2.COLOR_BGR2HSV) # 将BGR图像转化到HSV的颜色空间
|
||||
mask_blue = cv2.inRange(hsv, lower_blue, upper_blue)
|
||||
mask_yellow = cv2.inRange(hsv, lower_yellow, upper_yellow)
|
||||
mask_green = cv2.inRange(hsv, lower_green, upper_green)
|
||||
mask_plate = cv2.bitwise_or(mask_blue, mask_yellow)
|
||||
mask_plate = cv2.bitwise_or(mask_plate, mask_green)
|
||||
|
||||
# 根据阈值找到对应颜色
|
||||
mask = cv2.cvtColor(mask_plate, cv2.COLOR_GRAY2BGR)
|
||||
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
|
||||
Matrix = np.ones((20, 20), np.uint8)
|
||||
mask1 = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, Matrix)
|
||||
mask = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, Matrix) # 形态学开运算
|
||||
ret, mask = cv2.threshold(mask, 0, 255, cv2.THRESH_BINARY) # 二值化进而获取轮廓
|
||||
contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # 获取轮廓 contours
|
||||
|
||||
# 初始化 box
|
||||
box = None
|
||||
|
||||
# 寻找轮廓最大的 定位车牌
|
||||
for i in range(len(contours)):
|
||||
cnt = contours[i]
|
||||
area = cv2.contourArea(cnt)
|
||||
if area > 3000:
|
||||
rect = cv2.minAreaRect(cnt)
|
||||
box = cv2.boxPoints(rect)
|
||||
box = np.int_(box)
|
||||
break # 找到一个符合条件的就跳出循环
|
||||
|
||||
if box is None:
|
||||
raise ValueError("No contours found that meet the size requirement.")
|
||||
|
||||
plate = cv2.drawContours(car.copy(), [box], -1, (0, 255, 0), 3)
|
||||
|
||||
"""=========================== 2. 分割车牌中的每个字符 ==========================="""
|
||||
ys = [box[0, 1], box[1, 1], box[2, 1], box[3, 1]]
|
||||
xs = [box[0, 0], box[1, 0], box[2, 0], box[3, 0]]
|
||||
ys_sorted_index = np.argsort(ys)
|
||||
xs_sorted_index = np.argsort(xs)
|
||||
x1 = box[xs_sorted_index[0], 0]
|
||||
x2 = box[xs_sorted_index[3], 0]
|
||||
y1 = box[ys_sorted_index[0], 1]
|
||||
y2 = box[ys_sorted_index[3], 1]
|
||||
ROI_plate = plate[y1:y2, x1:x2]
|
||||
ROI_plate_gray = cv2.cvtColor(ROI_plate, cv2.COLOR_BGR2GRAY) # 灰度化
|
||||
ROI_plate_blur = cv2.GaussianBlur(ROI_plate_gray, (5, 5), 0) # 高斯滤波
|
||||
ret, ROI_plate_Binary = cv2.threshold(ROI_plate_blur, 127, 255, cv2.THRESH_BINARY) # 二值化
|
||||
# 形态学腐蚀 去除边框
|
||||
kernel = np.ones((5, 5), dtype=np.uint8)
|
||||
ROI_erode = cv2.erode(ROI_plate_Binary, kernel, iterations=1)
|
||||
# 根据宽度 裁剪7个字符
|
||||
width = ROI_erode.shape[1]
|
||||
height = ROI_erode.shape[0]
|
||||
word_0 = ROI_erode[0:height, 0:np.uint8(height / 2)]
|
||||
word_1 = ROI_erode[0:height, np.uint8(height / 2):height]
|
||||
size = np.uint8((width - height) / 5)
|
||||
word_2 = ROI_erode[0:height, height + 0 * size:height + 1 * size]
|
||||
word_3 = ROI_erode[0:height, height + 1 * size:height + 2 * size]
|
||||
word_4 = ROI_erode[0:height, height + 2 * size:height + 3 * size]
|
||||
word_5 = ROI_erode[0:height, height + 3 * size:height + 4 * size]
|
||||
word_6 = ROI_erode[0:height, height + 4 * size:height + 5 * size]
|
||||
word_all = [word_0, word_1, word_2, word_3, word_4, word_5, word_6]
|
||||
return plate, word_all
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
car = cv2.imread(r'/mnt/data/cropped_license_plate_0.jpg', 1)
|
||||
plate, _ = car_plate_recognize(car)
|
||||
cv2.imwrite("plate.jpg", plate)
|
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 27 KiB |
@ -0,0 +1,15 @@
|
||||
import gradio as gr
|
||||
from tab1_1 import img_handle_1
|
||||
from tab1_2 import img_handle_2
|
||||
from tab1_3 import img_handle_3
|
||||
from tab2 import Car_segmentation
|
||||
from tab3 import Car_detection
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
gr.close_all()
|
||||
with gr.TabbedInterface(
|
||||
[img_handle_1(), img_handle_2(), img_handle_3(), Car_segmentation(), Car_detection()],
|
||||
["图像处理1:几何处理", "图像处理2:颜色空间变化", "图像处理3:频率像素点操作", "进阶功能:车牌定位与分割", "YOLO车牌检测与OCR识别"],
|
||||
) as demo:
|
||||
demo.launch(share=True)
|
@ -0,0 +1,91 @@
|
||||
# encoding:utf-8
|
||||
import cv2
|
||||
from PyQt5.QtGui import QPixmap, QImage
|
||||
import numpy as np
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import csv
|
||||
import os
|
||||
|
||||
# fontC = ImageFont.truetype("Font/platech.ttf", 20, 0)
|
||||
|
||||
# 绘图展示
|
||||
def cv_show(name,img):
|
||||
cv2.imshow(name, img)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
def drawRectBox(image, rect, addText, fontC, color=(0,0,255)):
|
||||
"""
|
||||
绘制矩形框与结果
|
||||
:param image: 原始图像
|
||||
:param rect: 矩形框坐标, int类型
|
||||
:param addText: 类别名称
|
||||
:param fontC: 字体
|
||||
:return:
|
||||
"""
|
||||
# 绘制位置方框
|
||||
cv2.rectangle(image, (rect[0], rect[1]),
|
||||
(rect[2], rect[3]),
|
||||
color, 2)
|
||||
|
||||
# 绘制字体背景框
|
||||
# cv2.rectangle(image, (rect[0] - 1, rect[1] - 50), (rect[2], rect[1]), color, -1, cv2.LINE_AA)
|
||||
# 图片 添加的文字 位置 字体 字体大小 字体颜色 字体粗细.无法正常显示中文
|
||||
# cv2.putText(image, addText, (int(rect[0])+2, int(rect[1])-3), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
|
||||
|
||||
# 可以显示中文
|
||||
# 字体自适应大小
|
||||
font_size = int((rect[3]-rect[1])/1.5)
|
||||
fontC = ImageFont.truetype("Font/platech.ttf", font_size, 0)
|
||||
img = Image.fromarray(image)
|
||||
draw = ImageDraw.Draw(img)
|
||||
draw.text((rect[0]+2, rect[1]-font_size), addText, (0, 0, 255), font=fontC)
|
||||
imagex = np.array(img)
|
||||
return imagex
|
||||
|
||||
|
||||
def img_cvread(path):
|
||||
# 读取含中文名的图片文件
|
||||
# img = cv2.imread(path)
|
||||
img = cv2.imdecode(np.fromfile(path, dtype=np.uint8), cv2.IMREAD_COLOR)
|
||||
return img
|
||||
|
||||
|
||||
def draw_boxes(img, boxes):
|
||||
for each in boxes:
|
||||
x1 = each[0]
|
||||
y1 = each[1]
|
||||
x2 = each[2]
|
||||
y2 = each[3]
|
||||
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
return img
|
||||
|
||||
|
||||
|
||||
def cvimg_to_qpiximg(cvimg):
|
||||
height, width, depth = cvimg.shape
|
||||
cvimg = cv2.cvtColor(cvimg, cv2.COLOR_BGR2RGB)
|
||||
qimg = QImage(cvimg.data, width, height, width * depth, QImage.Format_RGB888)
|
||||
qpix_img = QPixmap(qimg)
|
||||
return qpix_img
|
||||
|
||||
|
||||
|
||||
|
||||
# 封装函数:图片上显示中文
|
||||
def cv2AddChineseText(img, text, position, textColor=(0, 255, 0), textSize=50):
|
||||
if (isinstance(img, np.ndarray)): # 判断是否OpenCV图片类型
|
||||
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
||||
# 创建一个可以在给定图像上绘图的对象
|
||||
draw = ImageDraw.Draw(img)
|
||||
# 字体的格式
|
||||
fontStyle = ImageFont.truetype(
|
||||
"simsun.ttc", textSize, encoding="utf-8")
|
||||
# 绘制文本
|
||||
draw.text(position, text, textColor, font=fontStyle)
|
||||
# 转换回OpenCV格式
|
||||
return cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)
|
||||
|
||||
|
||||
|
|
After Width: | Height: | Size: 173 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 222 KiB |
After Width: | Height: | Size: 239 KiB |
After Width: | Height: | Size: 718 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 142 KiB |
After Width: | Height: | Size: 180 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 372 KiB |
After Width: | Height: | Size: 434 KiB |
After Width: | Height: | Size: 561 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 271 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 172 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 127 KiB |
After Width: | Height: | Size: 217 KiB |
@ -0,0 +1,49 @@
|
||||
import gradio as gr
|
||||
from img_enhancement import Image_enhancement
|
||||
|
||||
"""1.1 对图像进行几何处理:图片旋转、图片缩放"""
|
||||
|
||||
# 类实例化
|
||||
img_enhance = Image_enhancement()
|
||||
|
||||
def img_handle_1():
|
||||
def pridict_1(query_image=None,angle=30):
|
||||
img_roate = img_enhance.roate(query_image, angle)
|
||||
return img_roate
|
||||
|
||||
def pridict_2(query_image=None,w=224,h=224):
|
||||
img_resized = img_enhance.resize(query_image, int(w), int(h))
|
||||
return img_resized
|
||||
|
||||
title = "<h1 align='center'>图像处理操作1:几何处理</h1>"
|
||||
description = "1.对图像进行几何处理:图片旋转、图片缩放" # "频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(title)
|
||||
gr.Markdown(description)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
img = gr.components.Image(label="图片")
|
||||
angle_num = gr.components.Slider(minimum=0, maximum=360, step=5, value=45, label="选择要旋转的角度")
|
||||
btn_1 = gr.Button("图片旋转", )
|
||||
|
||||
w = gr.Number(label="图片缩放宽为:",value=224)
|
||||
h = gr.Number(label="图片缩放高为:", value=224)
|
||||
btn_2 = gr.Button("图片缩放", )
|
||||
|
||||
with gr.Column(scale=1):
|
||||
out = gr.components.Image(label="处理后的图片为", height="auto")
|
||||
|
||||
btn_1.click(fn=pridict_1, inputs=[img, angle_num], outputs=out)
|
||||
|
||||
btn_2.click(fn=pridict_2, inputs=[img, w,h], outputs=out)
|
||||
|
||||
return demo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with gr.TabbedInterface(
|
||||
[img_handle_1()],
|
||||
["图像处理1:几何处理"],
|
||||
) as demo:
|
||||
demo.launch()
|
@ -0,0 +1,55 @@
|
||||
import gradio as gr
|
||||
from img_enhancement import Image_enhancement
|
||||
|
||||
"""1.2 对图像进行颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化"""
|
||||
|
||||
# 类实例化
|
||||
img_enhance = Image_enhancement()
|
||||
|
||||
def img_handle_2():
|
||||
def pridict_1(query_image=None,brightness=10,hue=10,contrast=10,saturation=10):
|
||||
img_Color = img_enhance.ColorJitter(query_image, brightness,hue,saturation,contrast)
|
||||
return img_Color
|
||||
|
||||
def pridict_2(query_image=None,method="灰度化"):
|
||||
if method=="灰度化":
|
||||
img_out = img_enhance.ToGray(query_image)
|
||||
elif method=="直方图均衡化":
|
||||
img_out = img_enhance.equalhist(query_image)
|
||||
return img_out
|
||||
|
||||
title = "<h1 align='center'>图像处理操作2:颜色空间变化</h1>"
|
||||
description = "2.对图像进行颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化" # "颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化;" "频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(title)
|
||||
gr.Markdown(description)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
img = gr.components.Image(label="图片")
|
||||
brightness = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择亮度")
|
||||
hue = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择色调")
|
||||
contrast = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择对比度")
|
||||
saturation = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择饱和度")
|
||||
btn_1 = gr.Button("对比度调整", )
|
||||
|
||||
method = gr.components.Radio(label="算法选择", choices=["灰度化", "直方图均衡化"],
|
||||
value="灰度化",)
|
||||
btn_2 = gr.Button("点击转化", )
|
||||
|
||||
with gr.Column(scale=1):
|
||||
out = gr.components.Image(label="处理后的图片为", height="auto")
|
||||
|
||||
btn_1.click(fn=pridict_1, inputs=[img, brightness,hue,contrast,saturation], outputs=out)
|
||||
|
||||
btn_2.click(fn=pridict_2, inputs=[img, method], outputs=out)
|
||||
|
||||
return demo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with gr.TabbedInterface(
|
||||
[img_handle_2()],
|
||||
["图像处理2:颜色空间变化"],
|
||||
) as demo:
|
||||
demo.launch()
|
@ -0,0 +1,91 @@
|
||||
import gradio as gr
|
||||
from img_enhancement import Image_enhancement
|
||||
|
||||
"""1.3 对图像进行频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"""
|
||||
|
||||
# 类实例化
|
||||
img_enhance = Image_enhancement()
|
||||
|
||||
def img_handle_3():
|
||||
def pridict_1(query_image=None,method_1="高斯滤波",count=3):
|
||||
if method_1 == "高斯滤波":
|
||||
img_mohu = img_enhance.Gaussblur(query_image,count)
|
||||
elif method_1 == "随机模糊":
|
||||
img_mohu = img_enhance.Blur(query_image, count)
|
||||
else: # 中值滤波
|
||||
img_mohu = img_enhance.Medianblur(query_image, count=5)
|
||||
return img_mohu
|
||||
|
||||
def pridict_2(query_image=None,method_2="robert"):
|
||||
if method_2=="sobel":
|
||||
img_out = img_enhance.sobel(query_image)
|
||||
elif method_2=="Prewitt":
|
||||
img_out = img_enhance.Prewitt(query_image)
|
||||
else:#robert
|
||||
img_out = img_enhance.robert(query_image)
|
||||
return img_out
|
||||
|
||||
def pridict_3(query_image=None,method_3="高斯噪声",mean=0,sigma=30,percentage=10):
|
||||
if method_3=="高斯噪声":
|
||||
img_noise = img_enhance.add_gaussian_noise(query_image,mean,sigma)
|
||||
elif method_3=="椒盐噪声":
|
||||
img_noise = img_enhance.add_salt_and_pepper_noise(query_image, percentage)
|
||||
else:# 均值噪声
|
||||
img_noise = img_enhance.add_mean_noise(query_image, mean, sigma)
|
||||
return img_noise
|
||||
|
||||
def pridict_4(query_image=None,method_4="yes"):
|
||||
if method_4=="yes":
|
||||
img_detect= img_enhance.Canny(query_image)
|
||||
else: #no
|
||||
img_detect = query_image
|
||||
return img_detect
|
||||
|
||||
title = "<h1 align='center'>图像处理操作3:频率像素点操作</h1>"
|
||||
description = "3.对图像进行频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(title)
|
||||
gr.Markdown(description)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
img = gr.components.Image(label="图片")
|
||||
method_1 = gr.components.Radio(label="模糊算法选择", choices=["高斯滤波", "随机模糊","中值滤波"],
|
||||
value="高斯滤波", )
|
||||
count = gr.components.Slider(minimum=0, maximum=8, step=1, value=3, label="模糊次数")
|
||||
|
||||
btn_1 = gr.Button("模糊处理", )
|
||||
|
||||
method_2 = gr.components.Radio(label="算子选择", choices=["sobel", "Prewitt","robert"],
|
||||
value="robert",)
|
||||
btn_2 = gr.Button("锐化处理", )
|
||||
|
||||
method_3 = gr.components.Radio(label="添加噪声类型选择", choices=["高斯噪声", "椒盐噪声", "均值噪声"],
|
||||
value="高斯噪声", )
|
||||
mean = gr.components.Slider(minimum=0, maximum=100, step=2, value=0, label="均值")
|
||||
sigma = gr.components.Slider(minimum=0, maximum=100, step=2, value=30, label="标准差")
|
||||
percentage = gr.components.Slider(minimum=0, maximum=100, step=5, value=30, label="百分比")
|
||||
btn_3 = gr.Button("添加噪声", )
|
||||
|
||||
method_4 = gr.components.Radio(label="是否边缘检测", choices=["yes","no"],
|
||||
value="yes", )
|
||||
btn_4 = gr.Button("边缘检测", )
|
||||
|
||||
|
||||
with gr.Column(scale=1):
|
||||
out = gr.components.Image(label="处理后的图片为", height="auto")
|
||||
|
||||
btn_1.click(fn=pridict_1, inputs=[img, method_1,count], outputs=out)
|
||||
btn_2.click(fn=pridict_2, inputs=[img, method_2], outputs=out)
|
||||
btn_3.click(fn=pridict_3, inputs=[img, method_3,mean,sigma,percentage], outputs=out)
|
||||
btn_4.click(fn=pridict_4, inputs=[img,method_4], outputs=out)
|
||||
|
||||
return demo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with gr.TabbedInterface(
|
||||
[img_handle_3()],
|
||||
["图像处理3:频率像素点操作"],
|
||||
) as demo:
|
||||
demo.launch()
|
@ -0,0 +1,40 @@
|
||||
import gradio as gr
|
||||
import cv2
|
||||
from carPlate_recognize import car_plate_recognize
|
||||
|
||||
def Car_segmentation():
|
||||
def pridict(query_image=None):
|
||||
img_cvt = cv2.cvtColor(query_image, cv2.COLOR_BGR2RGB)
|
||||
plate, word_all = car_plate_recognize(img_cvt)
|
||||
return plate,word_all
|
||||
|
||||
title = "<h1 align='center'>基于Opencv图像处理的车牌定位和分割</h1>"
|
||||
description = "对输入的车牌进行车牌的定位与分割操作"
|
||||
examples = [['images/car.jpg'],['images/car.png'],['images/car_test.jpg']]
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(title)
|
||||
gr.Markdown(description)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
#with gr.Column(scale=2):
|
||||
img = gr.components.Image(label="图片")
|
||||
btn = gr.Button("点击定位与分割", )
|
||||
with gr.Column(scale=1):
|
||||
out_1 = gr.components.Image(label="车牌定位:",height="auto")
|
||||
out_2 = gr.Gallery(label="车牌分割:",columns=[4], height="auto",object_fit="contain")
|
||||
|
||||
inputs = [img]
|
||||
outputs = [out_1,out_2]
|
||||
btn.click(fn=pridict, inputs=inputs, outputs=outputs)
|
||||
gr.Examples(examples, inputs=inputs)
|
||||
|
||||
return demo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with gr.TabbedInterface(
|
||||
[Car_segmentation()],
|
||||
["Opencv车牌定位与分割"],
|
||||
) as demo:
|
||||
demo.launch(show_api=False,inbrowser=False,)#auth=("admin", '1234')
|
@ -0,0 +1,84 @@
|
||||
import gradio as gr
|
||||
import cv2
|
||||
import time
|
||||
from ultralytics import YOLO
|
||||
from paddleocr import PaddleOCR
|
||||
import numpy as np
|
||||
import detect_tools as tools
|
||||
from imgTest import get_license_result
|
||||
import os
|
||||
|
||||
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
||||
|
||||
# 加载YOLOv8检测模型
|
||||
model_path = 'models/best.pt'
|
||||
yolo_model = YOLO(model_path, task='detect')
|
||||
|
||||
# 加载车牌识别模型
|
||||
cls_model_dir = 'paddleModels/whl/cls/ch_ppocr_mobile_v2.0_cls_infer'
|
||||
rec_model_dir = 'paddleModels/whl/rec/ch/ch_PP-OCRv4_rec_infer'
|
||||
ocr = PaddleOCR(use_angle_cls=False, lang="ch", det=False, cls_model_dir=cls_model_dir, rec_model_dir=rec_model_dir)
|
||||
|
||||
|
||||
def Car_detection():
|
||||
def predict_image(query_image):
|
||||
start_time = time.time()
|
||||
|
||||
# 图像预处理
|
||||
img = cv2.cvtColor(query_image, cv2.COLOR_BGR2RGB)
|
||||
print(f"Image preprocessing time: {time.time() - start_time:.2f}s")
|
||||
|
||||
# 使用YOLOv8检测车辆和车牌位置
|
||||
yolo_start = time.time()
|
||||
results = yolo_model(img)[0]
|
||||
yolo_output = img.copy() # 复制原图像用于显示YOLO结果
|
||||
location_list = results.boxes.xyxy.tolist()
|
||||
print(f"YOLO detection time: {time.time() - yolo_start:.2f}s")
|
||||
|
||||
# 处理每个检测到的车牌区域
|
||||
license_numbers = []
|
||||
for location in location_list:
|
||||
x1, y1, x2, y2 = list(map(int, location))
|
||||
crop_img = img[y1:y2, x1:x2]
|
||||
|
||||
# 使用PaddleOCR识别车牌号
|
||||
license_num, confidence = get_license_result(ocr, crop_img)
|
||||
if license_num:
|
||||
license_numbers.append(license_num)
|
||||
else:
|
||||
license_numbers.append("无法识别")
|
||||
|
||||
# 在YOLO结果图上绘制检测框
|
||||
cv2.rectangle(yolo_output, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
|
||||
return yolo_output, "\n".join(license_numbers)
|
||||
|
||||
title = "<h1 align='center'>基于Opencv图像处理的车牌检测与识别</h1>"
|
||||
description = "上传一张包含车辆的图像,系统将检测车辆并识别车牌号码"
|
||||
# examples = [['images/car.jpg'], ['images/car.png'], ['images/car_test.jpg']]
|
||||
|
||||
with gr.Blocks() as demo:
|
||||
gr.Markdown(title)
|
||||
gr.Markdown(description)
|
||||
with gr.Row():
|
||||
with gr.Column(scale=1):
|
||||
img = gr.components.Image(label="上传图片")
|
||||
btn = gr.Button("点击检测与识别")
|
||||
with gr.Column(scale=1):
|
||||
out_1 = gr.components.Image(label="YOLO定位结果:", height="auto")
|
||||
out_2 = gr.components.Textbox(label="车牌识别结果:", type="text", lines=6)
|
||||
|
||||
inputs = [img]
|
||||
outputs = [out_1, out_2]
|
||||
btn.click(fn=predict_image, inputs=inputs, outputs=outputs)
|
||||
# gr.Examples(examples, inputs=inputs)
|
||||
|
||||
return demo
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with gr.TabbedInterface(
|
||||
[Car_detection()],
|
||||
["Opencv车牌检测与识别"],
|
||||
) as demo:
|
||||
demo.launch(show_api=False, inbrowser=True)
|