前提・実現したいこと
画像の類似度をヒストグラムで図りたいのですが
openCVでエラーが出てしまい直し方がまったくわかりません。。。
良ければ教えてくれないでしょうか。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "C:\Users\NADA21\Documents\images\hist_matching.py", line 15, in <module> target_img = cv2.resize(target_img, IMG_SIZE) cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
該当のソースコード
python3
1# -*- coding: UTF-8 -*- 2 3"""hist matching.""" 4 5import cv2 6import os 7 8TARGET_FILE = '05.png' 9IMG_DIR = os.path.abspath(os.path.dirname(__file__)) + '/inu/' 10IMG_SIZE = (200, 200) 11 12target_img_path = IMG_DIR + TARGET_FILE 13target_img = cv2.imread(target_img_path) 14target_img = cv2.resize(target_img, IMG_SIZE) 15target_hist = cv2.calcHist([target_img], [0], None, [256], [0, 256]) 16 17print('TARGET_FILE: %s' % (TARGET_FILE)) 18 19files = os.listdir(IMG_DIR) 20for file in files: 21 if file == '.DS_Store' or file == TARGET_FILE: 22 continue 23 24 comparing_img_path = IMG_DIR + file 25 comparing_img = cv2.imread(comparing_img_path) 26 comparing_img = cv2.resize(comparing_img, IMG_SIZE) 27 comparing_hist = cv2.calcHist([comparing_img], [0], None, [256], [0, 256]) 28 29 ret = cv2.compareHist(target_hist, comparing_hist, 0) 30 print(file, ret) 31 32
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/28 05:45
2018/09/28 05:51
2018/09/28 06:19
2018/09/28 06:24 編集
2018/09/28 06:51
2018/09/28 06:54
2018/09/28 09:20