python opencv学習ノート
1265 ワード
画像の拡大・縮小
image=cv2.imread('test.jpg') res=cv2.resize(image,(32,32),interpolation=cv2.INTER_CUBIC) cv2.imshow('iker',res) cv2.imshow('image',image) cv2.waitKey(0) cv2.destoryAllWindows()
OpenCVとPythonの画像の読み込みと表示およびNumpyによる画像変換
mxnet画像をopencvのタイプに変換し、保存
img = mx.image.imdecode(s).asnumpy()
# plt.imshow(img)
# plt.title('id=' + str(i) + 'label=' + str(header.label))
# plt.savefig("mxshow/label_" + str(header.label) + '_id_' + str(i) + ".jpg")
# plt.pause(1)
label = str(header.label)
label = label.strip().split(".")[0]
print("all num " + str(all) + " current index "+str(i)+" process "+str(i * 100.0 / all)+"%")
label_dir = os.path.join(decode_path, label)
if not os.path.isdir(label_dir): # Create the log directory if it doesn't exist
label_num += 1
os.makedirs(label_dir)
X = img
print(X.shape)
X = cv2.cvtColor(X, cv2.COLOR_RGB2BGR)
X = cv2.resize(X,(160,160), interpolation=cv2.INTER_CUBIC)
cv2.imwrite(label_dir + "/label_" + str(label) + '_id_' + str(i) + ".jpg", X)