小编liz*_*ard的帖子

TypeError:src不是一个numpy数组,也不是标量

    gray_image = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY)

TypeError: src is not a numpy array, neither a scalar
Run Code Online (Sandbox Code Playgroud)

我目前正在努力解决这个问题,任何帮助将不胜感激.如评论中所述,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,\ …
Run Code Online (Sandbox Code Playgroud)

python opencv numpy image-processing python-2.7

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

image-processing ×1

numpy ×1

opencv ×1

python ×1

python-2.7 ×1