处理数据集用 彩色和黑白代码

彩色代码 10个里面取一个然后重新命名成1开始的JPG

import os
import cv2 as cv
j=1
dir_img="./color/"
list_img = os.listdir(dir_img)#获取目录下所有图片名
for i in range(1,len(list_img)):
    if i%10 == 0:
     name = str(i)+"_Color"+".bmp"
     path = os.path.join(dir_img,name)
     img = cv.imread(path)
     colorname = str(j)+".jpg"
     cv.imwrite("./color/"+colorname,img)
     j=j+1
    else:  
     name = str(i)+"_Color"+".bmp"
     path = os.path.join(dir_img,name)
     os.remove(path)

 然后黑白代码 同彩色 但是kinect出来的深度是3通道的 还要转换

 

import os
import cv2 as cv

j=1

dir_img="./depth/"
list_img = os.listdir(dir_img)#获取目录下所有图片名
for i in range(1,len(list_img)):
    if i%10 == 0:
      name = str(i)+"_depth"+".bmp"
      path = os.path.join(dir_img,name)
      img = cv.imread(path)
      #print(img)
      gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
      #print(gray)
      deepname = str(j)+".png"
      deeppath = os.path.join(dir_img,deepname)
      cv.imwrite(deeppath,gray)
      j=j+1
    else:  
     name = str(i)+"_depth"+".bmp"
     path = os.path.join(dir_img,name)
     os.remove(path)

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页