代码之家  ›  专栏  ›  技术社区  ›  Yehya Hattem

楼层平面图房间按名称着色

  •  0
  • Yehya Hattem  · 技术社区  · 1 年前

    我的目标是根据每个房间上写的单词为楼层平面图中的每个房间上色。 例如,如果写的单词是“卧室”,就把它涂成蓝色,以此类推。 我对之前在这里发现的一个代码进行了一些调整,该代码随机为每个房间上色。 为了使该代码发挥作用,必须关闭房间才能将其识别为一个单独的轮廓,所以我不得不用油漆手动关闭房间,直到我制定了关闭代码(我也愿意就此事提出建议,但这不是主要问题)

    我使用了阿拉伯语OCR库:

    image_path='/content/Y2.jpg'
    out_image='out.jpg'
    results=arabicocr.arabic_ocr(image_path,out_image)
    

    结果变量包含3个内容:(“单词周围轮廓的坐标”、“阿拉伯单词”和“阿拉伯单词准确的置信度”) 以下是输出示例:

    [[[106, 322], [138, 322], [138, 386], [106, 386]], '٣', 0.3450655038380312], [[[742, 412], [832, 412], [832, 456], [742, 456]], 'غرفة', 0.9943901896476746], [[[834, 386], [866, 386], [866, 450], [834, 450]], '؟', 0.9946355239663696], [[[490, 440], [518, 440], [518, 478], [490, 478]], '8', 0.9978250183434092]
    

    arabic_ocr库的out_image看起来是这样的(但这不是我想要的)

    我想要的是一个看起来更像这样的图像:

    但每个房间都按照书面文字着色

    这是主要代码:

    gap_in_wall_threshold=1000
    ret, labels = cv2.connectedComponents(thresh)
    image = cv2.cvtColor(thresh,cv2.COLOR_GRAY2RGB)
    unique = np.unique(labels)
    rooms = []
    
    
    for i in range(len(results)):
    
      if is_float(results[i][1]) or contains_arabic_numeral(results[i][1]) or results[i][1]=='' or results[i][1]=='؟':
        continue
    
      else:
        x,y = results[i][0][0]
        for label in unique:
            component = labels == label
            #print(component,"= component")
            if image[component].sum() == 0 or np.count_nonzero(component) < gap_in_wall_threshold:
                color = 0
                image[component]=color
            else:
    
                if component[x, y] :
                    color = Room_Color(results[i][1])
                    #color = np.random.randint(0, 255, size=3)
                    rooms.append(component)
                    image[component] = color
    
                else:
                    color = [0,0,0]
                    image[component] = color
    
    
    cv2_imshow(image)
    

    代码给了我一个黑色图像,我无法识别问题,有人能帮我吗?

    0 回复  |  直到 1 年前