python的OpenCV和glob遍历图片文件夹中文乱码

最近我在做一个课程设计,遇到要遍历中文文件夹的问题,刚开始不能,就翻译为英文,最后老师要求中文也可以用,所以我来告诉大家一个冷门又古老的函数,就是为解决中文编码问题,这个锅不要怪python,只能说OpenCV比较坑,下面上代码

def reading_images(fruit_img, fruit_labels, img_folder):
    # reading_images: a function that does the following steps:
    # 1. store the image pixels to fruit_img, and the label names to fruit_labels
    # 2. Read every image
    # 3. resize the images
    # 4. standardize the images
    # 5. return a list of image pixels ,hog freature and a list of labels
    for fruit_dir_path in glob.glob(img_folder):
        fruit_name = fruit_dir_path.split("\\")[-1]
        print(fruit_dir_path)
        for image_path in glob.glob(os.path.join(fruit_dir_path,'*.jpg')):
            print(image_path)
            image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8),1)

主要是

image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8),1)

的功劳,大家可以百度一下这个OpenCV的函数

转载于:https://my.oschina.net/u/2335092/blog/1815396

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值