【问题标题】:How to detect and change colours in RGB picture如何检测和改变RGB图片中的颜色
【发布时间】:2021-04-22 00:13:24
【问题描述】:

给定下一张图片:

robot = io.imread('robot.png')

机器人将是一个 1277x789x3 RGB 矩阵。

问题是我想把机器人的橙色变成紫色,像这样:

问题是我不知道如何检测机器人的橙色。有什么建议吗?

【问题讨论】:

    标签: python computer-vision


    【解决方案1】:

    我在这里发现了类似的问题:I want to change the colors in image with python from specific color range to another color

    按照上面链接中的代码并更改一些参数:

    #!/usr/local/bin/python3
    import cv2 as cv
    import numpy as np
    
    # Load the aerial image and convert to HSV colourspace
    image = cv.imread("path/image.jpg")
    hsv=cv.cvtColor(image,cv.COLOR_BGR2HSV)
    
    # Define lower and uppper limits of what we call "orange"
    orange_lo=np.array([10,100,20])
    orange_hi=np.array([30,255,255])
    
    # Mask image to only select oranges
    mask=cv.inRange(hsv,orange_lo,orange_hi)
    
    # Change image to purple where we found orange
    image[mask>0]=(188,0,188)
    
    cv.imwrite("result.png",image)
    

    【讨论】:

      猜你喜欢
      • 2022-07-11
      • 2012-01-20
      • 2016-02-29
      • 1970-01-01
      • 2020-03-02
      • 2016-06-18
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      相关资源
      最近更新 更多