zoukankan      html  css  js  c++  java
  • PIL-Image、ImageDraw图像标记

     用方框标记图片

    from PIL import Image
    from PIL import ImageDraw
    info = {"Match_Lat": "36.8890532", 
    "LinkID": "42435642N",  
    "BboxID": "ImageID": 
    "timg.jpg",
    "Pos_X": "360", 
    "Pos_Y": "260",  
    "Pos_W": "80", 
    "Pos_H": "70",…………….}
    
    
    def rectangle():
        img_name=info['ImageID']
        base = Image.open(img_name).convert('RGBA')
        d = ImageDraw.Draw(base)
        # rectangle(xy,fill, outline)
        # xy给出rectangle的左上和右下的像素点坐标,fill填充,outline是pencolor。
        pox_x=info['Pos_X']   #识别框图片坐标x
        pox_y=info['Pos_Y']   #识别框图片坐标x
        pox_h=info['Pos_H']
        pox_w=info['Pos_W']
        print([int(pox_x),int(pox_y),pox_h,pox_w])
        d.rectangle([int(pox_x), int(pox_y), int(pox_x)+int(pox_w), int(pox_y)+int(pox_h)], outline='RED')  # 加入fill="red"的话,就可以填充颜色
        #d.rectangle([60,30,120,80],outline='white')  #加入fill="red"的话,就可以填充颜色
        base.save('rectangle.png')
        base.close()
    
    rectangle()
    

      

    效果展示

  • 相关阅读:
    grunt 使用比较
    一些技术要点
    git 使用笔记
    oo的一些概念
    借用构造函数继承非原型
    bower解决js的依赖管理
    需要了解的一些东西
    一些常用的代码
    js模式(一):单例模式
    写给自己的计划
  • 原文地址:https://www.cnblogs.com/djfboai/p/11363281.html
Copyright © 2011-2022 走看看