0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Open CV エラー error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' -> Numpy.fromfileを使用する

Last updated at Posted at 2021-11-17

以下の様に<ダウンロード1.JPG>を表示させるプログラムを実行した。

import cv2 as cv

image_picture = 'Resources/ダウンロード1.JPG'
img = cv.imread(image_picture)
cv.imshow('IMAGE',img)
cv.waitKey(0)

結果、エラーを検知

error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

調査したところ、今回の場合はファイル名にカタカナが使用されていることが原因という仮説が立った。そのため、こちらの記事を参考にしてNumpy.fromfileを使用して修正を試みた。
http://solasyndrome.blog.fc2.com/blog-entry-16.html

import cv2 as cv
import numpy as np

image_picture = np.fromfile("Resources/ダウンロード1.JPG", dtype=np.uint8)
img = cv.imdecode(image_picture, cv.IMREAD_COLOR)
cv.imshow('IMAGE', img)
cv.waitKey(0)

無事、表示に成功。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?