检测颜色不在创建的颜色图中

问题描述

检测图像中的颜色时出现问题。如果我读取图像的所有像素,则检测到的所有颜色都是正确的。我的意思是,我有一张具有13种不同颜色的图像,并制作了地图颜色,除了这13种不同颜色之外,没有检测到其他颜色。

读取所有像素的代码是:

def get_all_colors(self):
    sc = ShotColors()
    image = ShotChartImage(IMAGES.TEST_COLOUR_MAP)
    list_of_colors = sc.maristas_colors
    colors = {}
    for c in list_of_colors.keys():
        colors[c] = 0
    other_colors = {}
    errors = 0
    for y in range(image.image.height):
        for x in range(image.image.width):
            color = image.get_color(x,y)
            if color in list_of_colors:
                colors[color] = colors[color] + 1
            else:
                errors = errors + 1
                if color in other_colors:
                    other_colors[color] = other_colors[color] + 1
                else:
                    other_colors[color] = 1
    print(f"Colors matched: {colors}\n colors matched: {len(colors.keys())}")
    for k,v in sorted(colors.items(),key=itemgetter(1),reverse=True):
        print (k,v)
    print(f"Other colors: {other_colors})\ntotal other colors: {len(other_colors.keys())}")
    print(f"errors: {errors}")

变量list_of_colors是具有以下值的字典:

self.maristas_colors = {
    "#C49812" : "C3R","#704414" : "E3R","#98817C" : "Ce3R","#00E0EE" : "MBR","#F40084" : "MER","#00FF1E" : "PR","#FF0000" : "PC","#0054FF" : "PL","#EEE600" : "MEL","#7F4D68" : "MBL","#036860" : "Ce3L","#198D32" : "E3L","#F8A9D4" : "C3L"
}

我正在制作地图颜色的图像是:

enter image description here

将地图颜色制成的结果是:

Colors matched: {'#C49812': 1119,'#704414': 5435,'#98817C': 20510,'#00E0EE': 6802,'#F40084': 4854,'#00FF1E': 2912,'#FF0000': 2800,'#0054FF': 2912,'#EEE600': 4805,'#7F4D68': 7458,'#036860': 20899,'#198D32': 7293,'#F8A9D4': 1313}
 colors matched: 13

Other colors: {})
total other colors: 0
errors: 0

但是,如果我尝试获取确定的像素的颜色,我发现self.maristas_colors中没有颜色的像素始终是相同的颜色:#000000(黑色)。

代码是:

def set_positions(self):
    '''Set the place in the field of each shoot'''
    sc = ShotColors()
    list_of_colors = sc.maristas_colors
    images = self.load_images()
    colors = {}
    for c in list_of_colors.keys():
        colors[c] = 0
    other_colors = {}
    self.errors = 0
    for index,row in self.df.iterrows():
        image = self.select_image(images,row["team"])
        color = image.get_color(row["x"],row["y"])
        if color in list_of_colors:
            self.df.at[index,"position"] = list_of_colors[color]
            colors[color] = colors[color] + 1
        else:
            self.errors = self.errors + 1
            if color in other_colors:
                other_colors[color] = other_colors[color] + 1
            else:
                other_colors[color] = 1
    print(f"colors: {colors}\n total_colors: {len(colors.keys())}")
    print(f"other colors: {other_colors}\n total other colors: {len(other_colors.keys())}")
    print(f"errores: {self.errors}")

使用此代码尝试检测某些像素的颜色的结果是:

colors: {'#C49812': 1,'#704414': 5,'#98817C': 13,'#00E0EE': 198,'#F40084': 120,'#00FF1E': 225,'#FF0000': 331,'#0054FF': 203,'#EEE600': 94,'#7F4D68': 265,'#036860': 37,'#198D32': 21,'#F8A9D4': 12}
 total_colors: 13

other colors: {'#000000': 21}
 total other colors: 1

那怎么可能?我在做错什么吗?

修改我:

我发现了问题。在从像素获取颜色之前,我先旋转图像。如果我取消旋转,那么我得到的颜色是正确的。

怎么可能?旋转图像后如何始终从像素获得黑色?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...