python - 从图像方法中脱毛
问题描述
我试图去除头发 reom 一组皮肤图像
这是加载图像的代码
DIRECTORY = r'/gdrive/MyDrive/Train4'
CATEGORIES = ["h","m","v","s","a","Unknown"]
data = []
labels = []
for category in CATEGORIES:
path = os.path.join(DIRECTORY,category)
label= CATEGORIES.index(category)
for img in os.listdir(path):
img_path = os.path.join(path, img)
image = load_img(img_path, target_size=(1024,1024))
final_image = removing_hair(image)
image = cv2.resize(final_image,(224,224))
image = img_to_array(image)
image = preprocess_input(image)
data.append(image)
labels.append(label)
这是脱毛的方法
def removing_hair(image):
# convert image to grayScale
grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# kernel for morphologyEx
kernel = cv2.getStructuringElement(1,(17,17))
# apply MORPH_BLACKHAT to grayScale image
blackhat = cv2.morphologyEx(grayScale, cv2.MORPH_BLACKHAT, kernel)
# apply thresholding to blackhat
_,threshold = cv2.threshold(blackhat,10,255,cv2.THRESH_BINARY)
# inpaint with original image and threshold image
final_image = cv2.inpaint(image,threshold,1,cv2.INPAINT_TELEA)
return final_image
但我不断收到这个错误,我无法解决它
TypeError Traceback (most recent call last)
<ipython-input-16-6f8ff4af67a7> in <module>()
12 img_path = os.path.join(path, img)
13 image = load_img(img_path, target_size=(1024,1024))
---> 14 final_image = removing_hair(image)
15 image = cv2.resize(final_image,(224,224))
16 image = img_to_array(image)
<ipython-input-15-46bfec188a32> in removing_hair(image)
1 def removing_hair(image):
2 # convert image to grayScale
----> 3 grayScale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
4
5 # kernel for morphologyEx
TypeError: Expected Ptr<cv::UMat> for argument '%s'
有什么问题,我该如何解决
解决方案
推荐阅读
- java - 使用 Hibernate 持久化和查询多对象关系
- javascript - Discord.js 'ReferenceError: 要求未定义'
- python - 按键类型解构 json
- r - 将一列列表添加到 R 中的数据框
- node.js - Nodejs Swagger 无法向请求添加授权标头
- html - 如何制作内容居中的可点击响应方块?
- javascript - 如何检查:数组是否正确包含特定文本?
- firebase - Firebase 可以检测到异常数量的读/写吗?
- python - 有没有办法让网站显示长时间运行的 python 程序的正常运行时间和输出
- python - 使用 axios、flask 和 react 的 400 错误请求