使用 隐马尔可夫模型 进行图像识别

import os
import sys
import cv2 as cv
import numpy as np
import hmmlearn.hmm as hl # 伊马尔可夫模型
import warnings # 屏蔽不必要的报警提示信息,以免影响显示

def img_show(title, img):
“”"
显示图片
“”"
cv.imshow(title, img)

def search_objects(directory):
“”"
寻找给定目录下的文件
“”"
if not os.path.isdir(directory): # 检测给定路径是否为一个目录
raise IOError(“The director %s doesn’t exit” % directory )
objects = {} # 创建一个字典,用于保存目录中的文件
for curdir, subdirs, files in os.walk(directory): # os.walk(directory) 返回当前路径 子目录 和 当前路径下的文件
for jpeg in [file for file in files if file.endswith(".jpg")]: # 遍历所有的 .jpg 文件
path = os.path.join(curdir, jpeg) # 拼接目录 和 文件名
label = path.split(os.path.sep)[-2]
if label not in objects:
objects[label] = [] # 如果objects 中没有相应的 label时创建一个空列表
objects[label].append(path)
return objects

def read_image(filename):
“”“读取彩色图像并返回”""
img = cv.imread(filename)

猜你喜欢

转载自blog.csdn.net/u011532014/article/details/103917547