TypeError例外ではありません:srcがnumpyの配列ではないではありません、どちらもスカラー例外TypeError:srcがnumpyの配列、どちらもスカラー
gray_image = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY)
私は現在、これを解決するために働いている、任意の助けいただければ幸いです。コメントで述べたように、PILイメージはCV2形式に変換する必要があります。以下の例を使用して誰でも説明を提供できますか?
import cv2
import numpy as np
from matplotlib import pyplot as plt
from cycler import cycler
from PIL import Image, ImageEnhance
# Loads the image then enhances it
image = Image.open('lineCapture.png')
contrast = ImageEnhance.Contrast(image)
# Reads the enhanced image and converts it to grayscale, creates new file
gray_image = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY) //there is a problem here
cv2.imwrite('enhancedGrayscaleLineCapture.png', gray_image)
# Adaptive Gaussian Thresholding
th1 = cv2.adaptiveThreshold(gray_image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
# Otsu's thresholding
ret2,th2 = cv2.threshold(gray_image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Otsu's thresholding after Gaussian filtering
blur = cv2.GaussianBlur(gray_image,(5,5),0)
ret3,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# writes enhanced and thresholded img
cv2.imwrite('enhancedGrayscaleThresholdLineCapture.png', th2)
スレッショルドのある画像を見たい場合は、これを最終画像の書き込みに変更してください。 cv2.imwrite( 'enhancedGrayscaleThresholdCapture.png'、th2) –
@ I.Newtonありがとうございます。 – lizardwizard
@ I.Newtonここで画像の書き込み量を制御するにはどうすればよいですか?私が実行すると、私は本当に必要のないディスクに3つのファイルを書き込む。私は最後の拡張キャプチャが必要です。 – lizardwizard