【问题标题】:Reading BGR values of pixel in OpenCV在 OpenCV 中读取像素的 BGR 值
【发布时间】:2021-12-10 04:44:08
【问题描述】:

enter image description here我想检测图像中形状的颜色,所以当我运行代码时 “bgr_list = img[cX,cY]” 我收到此错误:

bgr_list = img[cX,cY]                 
IndexError: index 648 is out of bounds for axis 0 with size 598
        
        
but when I run "bgr_list = img[300,300]" I do not get any error  
->where [300,300] is white portion in image  
-> where, cX = x-coordinate of centroid and cY = y-coordinate of centroid  
-> BGR_list is bgr value of pixel at centroid  
-> the size of image is 898x598 pixel

【问题讨论】:

  • 只是猜测:尝试将索引行更改为bgr_list = img[cY,cX]
  • 感谢@DominikFicek,它成功了,你能告诉我反转坐标背后的逻辑吗?

标签: python-3.x opencv image-processing numpy-ndarray color-detection


【解决方案1】:

看起来你从某种预处理中获得了 X 和 Y 笛卡尔坐标,但是 opencv 使用的numpy 矩阵使用矩阵索引(row, column, channel)。您的 X 坐标对应于列索引,Y 坐标是您的行索引。

翻转索引应该可以完成工作 bgr_list = img[cY,cX]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 2017-07-01
    相关资源
    最近更新 更多