【问题标题】:Function that will take an index of an image and return its color将获取图像索引并返回其颜色的函数
【发布时间】:2018-10-11 10:12:05
【问题描述】:

我正在尝试编写一个函数,它将图像作为输入,然后返回一个函数,该函数将采用索引并返回该索引的颜色。这是我到目前为止得到的:

def generator(image):
    def index2color(index1): 
        return image[index1]
    return index2color

让我们试试吧:

 generator2 = generator("flower.jpg")
 print (generator2((3)))

 >>> w

所以这将返回字符串中的索引,而不是图片的索引。任何建议将不胜感激!

【问题讨论】:

  • 对图像进行操作即可。否则谷歌一下,互联网上有很棒的教程。

标签: python cv2


【解决方案1】:

您需要先将图像读入适当的对象,然后对图像对象进行操作。像这样:

flower_img = cv2.imread('flower.jpg')
generator2 = generator(flower_img)

考虑解决这个问题,以便更好地了解您可以做什么:https://docs.opencv.org/3.1.0/d3/df2/tutorial_py_basic_ops.html

【讨论】:

  • 谢谢!那是我缺少的部分。
猜你喜欢
  • 1970-01-01
  • 2016-01-25
  • 2021-10-07
  • 1970-01-01
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
  • 2018-04-27
  • 2010-12-17
相关资源
最近更新 更多