✨作者主页 :IT研究室✨
个人简介:曾从事计算机专业培训教学,擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。
☑文末获取源码☑
文章目录
一、前言
系统介绍
本系统名为《基于深度学习的塑料类型图像分类研究》,采用Python语言与Django框架搭建,核心识别能力由卷积神经网络(CNN)深度学习模型提供,面向塑料类型图像分类这一具体任务展开。系统围绕用户实际使用流程设计,包含系统首页、用户管理、塑料类型识别、识别历史管理等功能模块。其中塑料类型识别支持图片识别、视频识别与摄像头识别三种方式:用户上传图片后由训练好的CNN模型完成推理并返回塑料类别结果;视频识别按帧抽取图像送入模型逐帧判断并汇总输出;摄像头识别调用设备实时画面进行连续分类。每次识别产生的记录统一写入识别历史,便于用户回看与追溯。系统整体结构清晰、功能边界明确,适合作为计算机专业本科毕业设计的完整实现载体。
选题背景
塑料制品在日常生活中的使用量一直很大,废弃塑料的分类回收却长期依赖人工分拣,效率不高,准确率也容易受疲劳和主观判断影响。随着深度学习在图像分类领域逐渐成熟,用卷积神经网络自动识别塑料类型具备了一定的可行性,相关研究也多集中在模型结构与数据集构建上。对于计算机专业本科生来说,这类课题既能接触到图像预处理、模型训练与推理部署的完整链路,又不会因为任务过于庞大而难以在毕设周期内完成。目前公开的塑料图像分类实践项目中,把模型能力封装成可操作系统的案例并不多,多数只停留在训练脚本层面,缺少图片、视频、摄像头等多种输入方式与识别记录管理的整合。基于这一现状,本课题尝试把CNN图像分类模型与Django Web框架结合起来,做一个功能相对完整的塑料类型识别系统,让模型推理真正落到可交互的使用场景中。
选题意义
本课题的意义更多体现在学习与实践层面。从技术角度看,把CNN模型训练、推理与Django后端整合到同一个系统里,能帮助自己理清深度学习项目从数据到模型再到接口的完整流程,对图像预处理、模型加载、结果返回这些环节有更具体的认识。从应用角度看,系统提供图片、视频、摄像头三种识别入口,并保留识别历史,虽然规模不大、识别范围也有限,但至少呈现了一个可操作的塑料类型分类原型,能为后续想在此基础上扩展的人提供一个参考起点。从毕业设计本身看,课题目标明确、功能边界清楚,适合在有限时间内完成并验证,也能让自己在模型调试与后端联调中积累一些实际排错经验。整体来说,这个系统谈不上多大创新,更多是一次把课堂所学串起来的尝试。
二、系统界面展示
- 基于深度学习的塑料类型图像分类研究界面展示:








三、代码参考
- 项目实战代码参考:
java(贴上部分代码)
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("PlasticImageClassification").master("local[*]").getOrCreate()
def classify_single_image(request):
if request.method != "POST":
return JsonResponse({"code": 400, "msg": "请求方式错误"})
upload_file = request.FILES.get("image")
if not upload_file:
return JsonResponse({"code": 400, "msg": "未获取到上传图片"})
allowed_ext = [".jpg", ".jpeg", ".png", ".bmp"]
file_name = upload_file.name.lower()
ext = os.path.splitext(file_name)[1]
if ext not in allowed_ext:
return JsonResponse({"code": 400, "msg": "图片格式不支持"})
if upload_file.size > 10 * 1024 * 1024:
return JsonResponse({"code": 400, "msg": "图片大小超出限制"})
save_dir = os.path.join(settings.MEDIA_ROOT, "plastic_images")
if not os.path.exists(save_dir):
os.makedirs(save_dir)
save_name = str(uuid.uuid4()) + ext
save_path = os.path.join(save_dir, save_name)
with open(save_path, "wb+") as f:
for chunk in upload_file.chunks():
f.write(chunk)
img = Image.open(save_path).convert("RGB")
img = img.resize((224, 224))
img_array = np.array(img, dtype=np.float32) / 255.0
img_array = np.expand_dims(img_array, axis=0)
model = load_plastic_model()
pred = model.predict(img_array)
class_index = int(np.argmax(pred[0]))
confidence = float(np.max(pred[0]))
class_name = PLASTIC_CLASS_NAMES[class_index]
user_id = request.session.get("user_id")
if not user_id:
return JsonResponse({"code": 401, "msg": "请先登录"})
record = RecognitionHistory.objects.create(
user_id=user_id,
recognize_type="image",
source_file=save_name,
plastic_type=class_name,
confidence=round(confidence, 4),
create_time=timezone.now()
)
return JsonResponse({
"code": 200,
"msg": "识别成功",
"data": {
"record_id": record.id,
"plastic_type": class_name,
"confidence": round(confidence, 4)
}
})
def classify_video(request):
if request.method != "POST":
return JsonResponse({"code": 400, "msg": "请求方式错误"})
video_file = request.FILES.get("video")
if not video_file:
return JsonResponse({"code": 400, "msg": "未获取到上传视频"})
ext = os.path.splitext(video_file.name.lower())[1]
if ext not in [".mp4", ".avi", ".mov"]:
return JsonResponse({"code": 400, "msg": "视频格式不支持"})
if video_file.size > 100 * 1024 * 1024:
return JsonResponse({"code": 400, "msg": "视频大小超出限制"})
save_dir = os.path.join(settings.MEDIA_ROOT, "plastic_videos")
if not os.path.exists(save_dir):
os.makedirs(save_dir)
save_name = str(uuid.uuid4()) + ext
save_path = os.path.join(save_dir, save_name)
with open(save_path, "wb+") as f:
for chunk in video_file.chunks():
f.write(chunk)
cap = cv2.VideoCapture(save_path)
if not cap.isOpened():
return JsonResponse({"code": 500, "msg": "视频无法解析"})
frame_interval = 15
frame_index = 0
result_counter = {}
model = load_plastic_model()
while True:
ret, frame = cap.read()
if not ret:
break
if frame_index % frame_interval == 0:
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_resized = cv2.resize(frame_rgb, (224, 224))
frame_array = np.array(frame_resized, dtype=np.float32) / 255.0
frame_array = np.expand_dims(frame_array, axis=0)
pred = model.predict(frame_array)
idx = int(np.argmax(pred[0]))
name = PLASTIC_CLASS_NAMES[idx]
result_counter[name] = result_counter.get(name, 0) + 1
frame_index += 1
cap.release()
if not result_counter:
return JsonResponse({"code": 500, "msg": "视频中未提取到有效画面"})
main_type = max(result_counter, key=result_counter.get)
total_frames = sum(result_counter.values())
main_ratio = round(result_counter[main_type] / total_frames, 4)
user_id = request.session.get("user_id")
if not user_id:
return JsonResponse({"code": 401, "msg": "请先登录"})
record = RecognitionHistory.objects.create(
user_id=user_id,
recognize_type="video",
source_file=save_name,
plastic_type=main_type,
confidence=main_ratio,
create_time=timezone.now()
)
return JsonResponse({
"code": 200,
"msg": "视频识别完成",
"data": {
"record_id": record.id,
"main_plastic_type": main_type,
"main_ratio": main_ratio,
"frame_statistics": result_counter
}
})
def classify_camera_frame(request):
if request.method != "POST":
return JsonResponse({"code": 400, "msg": "请求方式错误"})
frame_file = request.FILES.get("frame")
if not frame_file:
return JsonResponse({"code": 400, "msg": "未获取到摄像头画面"})
if frame_file.size > 5 * 1024 * 1024:
return JsonResponse({"code": 400, "msg": "画面数据过大"})
frame_bytes = frame_file.read()
np_arr = np.frombuffer(frame_bytes, np.uint8)
frame = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
if frame is None:
return JsonResponse({"code": 400, "msg": "画面解码失败"})
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame_resized = cv2.resize(frame_rgb, (224, 224))
frame_array = np.array(frame_resized, dtype=np.float32) / 255.0
frame_array = np.expand_dims(frame_array, axis=0)
model = load_plastic_model()
pred = model.predict(frame_array)
class_index = int(np.argmax(pred[0]))
confidence = float(np.max(pred[0]))
class_name = PLASTIC_CLASS_NAMES[class_index]
user_id = request.session.get("user_id")
if not user_id:
return JsonResponse({"code": 401, "msg": "请先登录"})
last_record = RecognitionHistory.objects.filter(
user_id=user_id,
recognize_type="camera"
).order_by("-create_time").first()
if last_record and last_record.plastic_type == class_name:
last_record.confidence = round(confidence, 4)
last_record.create_time = timezone.now()
last_record.save()
record_id = last_record.id
else:
record = RecognitionHistory.objects.create(
user_id=user_id,
recognize_type="camera",
source_file="camera_frame",
plastic_type=class_name,
confidence=round(confidence, 4),
create_time=timezone.now()
)
record_id = record.id
return JsonResponse({
"code": 200,
"msg": "摄像头识别成功",
"data": {
"record_id": record_id,
"plastic_type": class_name,
"confidence": round(confidence, 4)
}
})
四、系统视频
基于深度学习的塑料类型图像分类研究项目视频:
结语
最新计算机毕业设计选题推荐-基于深度学习的塑料类型图像分类研究-运行部署-文档指导-深度学习-YOLO
想看其他类型的计算机毕业设计作品也可以和我说都有 谢谢大家!
有技术这一块问题大家可以评论区交流或者私我~
大家可以帮忙点赞、收藏、关注、评论啦~
源码获取:⬇⬇⬇