質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

4760閲覧

SSIM処理とMSE処理をした画像の表示

terertail

総合スコア12

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/12/05 05:54

実現したいこと

http://scikit-image.org/docs/dev/auto_examples/transform/plot_ssim.html
https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
上記のページに記載されているプログラムを合わせて、以下のページ
http://kamonohashiperry.com/archives/699
のような出力結果を出したいです。

発生している問題・エラーメッセージ

Traceback (most recent call last): File "C:\Users\Owner\compare.py", line 49, in <module> original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

該当のソースコード

# import the necessary packages from skimage import data, img_as_float from skimage.measure import compare_ssim as ssim import matplotlib.pyplot as plt import numpy as np import cv2 def mse(imageA, imageB): # the 'Mean Squared Error' between the two images is the # sum of the squared difference between the two images; # NOTE: the two images must have the same dimension err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2) err /= float(imageA.shape[0] * imageA.shape[1]) # return the MSE, the lower the error, the more "similar" # the two images are return err def compare_images(imageA, imageB, title): # compute the mean squared error and structural similarity # index for the images m = mse(imageA, imageB) s = ssim(imageA, imageB) # setup the figure fig = plt.figure(title) plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s)) # show first image ax = fig.add_subplot(1, 2, 1) plt.imshow(imageA, cmap = plt.cm.gray) plt.axis("off") # show the second image ax = fig.add_subplot(1, 2, 2) plt.imshow(imageB, cmap = plt.cm.gray) plt.axis("off") # show the images plt.show() # load the images -- the original, the original + contrast, # and the original + photoshop original = cv2.imread("resize/re_pic006.jpg") contrast = cv2.imread("resize/re_pic005.jpg") shopped = cv2.imread("resize/re_pic003.jpg") # convert the images to grayscale original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY) shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY) # initialize the figure fig = plt.figure("Images") images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped) # loop over the images for (i, (name, image)) in enumerate(images): # show the image ax = fig.add_subplot(1, 3, i + 1) ax.set_title(name) plt.imshow(image, cmap = plt.cm.gray) plt.axis("off") # show the figure plt.show() # compare the images compare_images(original, original, "Original vs. Original") compare_images(original, contrast, "Original vs. Contrast") compare_images(original, shopped, "Original vs. Photoshopped")

試したこと

読み込む画像を自分が用意したものでも同様のエラーとなりました。

補足情報(FW/ツールのバージョンなど)

python2.7.15
pip install opencv-pythonでOpenCVをインストール
opencv-python in c:~略~¥site-packages(3.4.4.19)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

t_obara

2018/12/05 07:03

エラー内容をご覧になり、どのような問題と思ったのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問