Răsfoiți Sursa

ai推送消息加上位置信息

lang 3 ani în urmă
părinte
comite
cbb2335721
3 a modificat fișierele cu 109 adăugiri și 17 ștergeri
  1. 3 2
      Controller/AiController.py
  2. 1 0
      Model/models.py
  3. 105 15
      Object/MergePic.py

Fișier diff suprimat deoarece este prea mare
+ 3 - 2
Controller/AiController.py


+ 1 - 0
Model/models.py

@@ -327,6 +327,7 @@ class Equipment_Info(models.Model):
     userID_id = models.CharField(default='',  db_index=True, blank=True, max_length=32, verbose_name=u'用户ID')
     is_st = models.SmallIntegerField(default=0, verbose_name='是否截图')  # 0 否,1 是图,2,视频
     storage_location = models.SmallIntegerField(default=1, verbose_name='数据信息存储位置。1:阿里云oss,2:aws')
+    borderCoords = models.TextField(default='', blank=True, verbose_name=u'ai类型图片边框位置信息')
     # message_id = models.CharField(blank=True, max_length=32, default='', verbose_name='第三方推送服务器返回的id')
     # push_type = models.SmallIntegerField(blank=True, default=0, verbose_name='第三方推送服务器标志。0:APNS推送,1:谷歌推送,2:极光推送')
     # push_server_status = models.IntegerField(blank=True, default=200, verbose_name='是否成功推送到第三方服务器。200:成功,other:失败')

+ 105 - 15
Object/MergePic.py

@@ -1,30 +1,41 @@
 import os
 
 import PIL.Image as Image
+from PIL import ImageDraw
 
 
 def resize_by_width(infile, image_size):
     """按照宽度进行所需比例缩放"""
     im = Image.open(infile)
-    (x, y) = im.size
-    lv = round(x / image_size, 2) + 0.01
-    x_s = int(x // lv)
-    y_s = int(y // lv)
-    print("x_s", x_s, y_s)
-    out = im.resize((x_s, y_s), Image.ANTIALIAS)
-    return out
+    if image_size != 0:
+        (x, y) = im.size
+        lv = round(x / image_size, 2) + 0.01
+        x_s = int(x // lv)
+        y_s = int(y // lv)
+        print("x_s", x_s, y_s)
+        out = im.resize((x_s, y_s), Image.ANTIALIAS)
+        return out
+    else:
+        (x_s, y_s) = im.size
+        print("x_s", x_s, y_s)
+        out = im.resize((x_s, y_s), Image.ANTIALIAS)
+        return out
 
 
 def get_new_img_xy(infile, image_size):
     """返回一个图片的宽、高像素"""
     im = Image.open(infile)
-    (x, y) = im.size
-    lv = round(x / image_size, 2) + 0.01
-    x_s = x // lv
-    y_s = y // lv
-    # print("x_s", x_s, y_s)
-    # out = im.resize((x_s, y_s), Image.ANTIALIAS)
-    return x_s, y_s
+    if image_size != 0:
+        (x, y) = im.size
+        lv = round(x / image_size, 2) + 0.01
+        x_s = x // lv
+        y_s = y // lv
+        # print("x_s", x_s, y_s)
+        # out = im.resize((x_s, y_s), Image.ANTIALIAS)
+        return x_s, y_s
+    else:   #等于0时按照原比例
+        (x_s, y_s) = im.size
+        return x_s, y_s
 
 
 # 定义图像拼接函数
@@ -82,11 +93,90 @@ def merge_images(image_dir_path,image_size,image_colnum):
     x_new = int(x_list[len(x_list) // 5 * 4])
     y_new = int(y_list[len(y_list) // 5 * 4])
     print(" x_new, y_new", x_new, y_new)
-    image_compose(image_colnum, image_size, image_rownum, image_fullpath_list, image_save_path, x_new, y_new)  # 调用函数
+    image_compose(image_colnum, image_size, image_rownum, image_fullpath_list, image_save_path, x_new, y_new)  # 调用函数.
+    return {'width':x_list[0],'height':sum(y_list),'num':len(y_list)}
     # for img_file in image_fullpath_list:
     #     resize_by_width(img_file,image_size)
 
+def pic_frame(image_path):
+    im = Image.open(image_path)
+    (x, y) = im.size
+
+    width_ratio =  0.5791387557983398
+    height_ratio = 0.23751300573349*(y*4)/y
+    # exit(height_ratio)
+    left_ratio = 0.24959583580493927
+    # exit(y*0.24852335453033447)
+    top_ratio = (y*4*0.504405677318573 - (2*y))/y
+    # exit(top_ratio)
+
+    draw = ImageDraw.Draw(im)
+    # draw.line([(10, 10), (50, 10), (50, 50), (10, 50), (10, 10)], fill=(255, 0, 0), width=5)
+
+    x1 = x*left_ratio
+    y1 = y*top_ratio
+
+    x2 = x1 + (width_ratio*x)
+    y2 = y1
+
+    x3 = x2
+    y3 = y1 + (height_ratio*y)
+
+    x4 = x1
+    y4 = y3
+
+    draw.line([(x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1)], fill=(255, 0, 0), width=3)
+    im.show()
+
+
 if __name__ == '__main__':
+    import PIL.Image as Image
+    from PIL import ImageDraw
+    import json
+
+    str = '[{"Width":0.07776174694299698,"Height":0.5436824560165405,"Top":0.36302846670150757,"Left":0.38370513916015625,"picName":"1647415509_0"},{"Width":0.10947742313146591,"Height":0.4826411008834839,"Top":0.4097094237804413,"Left":0.2790755331516266,"picName":"1647415509_0"},{"Width":0.2935298979282379,"Height":0.3697746992111206,"Top":0.621006965637207,"Left":0.6143953204154968,"picName":"1647415509_3"},{"Width":0.35492533445358276,"Height":0.8629811406135559,"Top":0.08606290817260742,"Left":0.3411630690097809,"picName":"1647415509_1"},{"Width":0.39604419469833374,"Height":0.38593751192092896,"Top":0.6001746654510498,"Left":0.060247838497161865,"picName":"1647415509_3"},{"Width":0.1105344295501709,"Height":0.5028191208839417,"Top":0.3258347511291504,"Left":0.0025259912945330143,"picName":"1647415509_3"},{"Width":0.13166509568691254,"Height":0.4821750223636627,"Top":0.34587907791137695,"Left":0.10105808824300766,"picName":"1647415509_3"},{"Width":0.22752150893211365,"Height":0.3825581967830658,"Top":0.5845961570739746,"Left":0.7430258989334106,"picName":"1647415509_3"},{"Width":0.1297324150800705,"Height":0.387117862701416,"Top":0.6101043224334717,"Left":0.4607183039188385,"picName":"1647415509_3"},{"Width":0.2157023847103119,"Height":0.94093257188797,"Top":0.06487464904785156,"Left":0.26413947343826294,"picName":"1647415509_2"},{"Width":0.23323440551757812,"Height":0.8104973435401917,"Top":0.18303179740905762,"Left":0.4748744070529938,"picName":"1647415509_2"},{"Width":0.31273096799850464,"Height":0.9365510940551758,"Top":0.05696296691894531,"Left":0.6696768999099731,"picName":"1647415509_2"},{"Width":0.27037277817726135,"Height":0.8783474564552307,"Top":0.12225198745727539,"Left":0.053227268159389496,"picName":"1647415509_2"},{"Width":0.5476366281509399,"Height":0.4337165951728821,"Top":0.45788294076919556,"Left":0.38325461745262146,"picName":"1647415509_0"}]'
+    str = json.loads(str)
+    for label in str:
+        im = Image.open('D:/devcode/ASJServer_test/static/ai/RBF474J66TLAGHW9111A/1647415509/'+label['picName'] + '.jpg')
+
+        (x, y) = im.size
+
+        width_ratio = label['Width']
+        height_ratio = label['Height']
+        # exit(height_ratio)
+        left_ratio = label['Left']
+        # exit(y*0.24852335453033447)
+        top_ratio = label['Top']
+        # exit(top_ratio)
+
+        draw = ImageDraw.Draw(im)
+        # draw.line([(10, 10), (50, 10), (50, 50), (10, 50), (10, 10)], fill=(255, 0, 0), width=5)
+
+        x1 = x * left_ratio
+        y1 = y * top_ratio
+
+        x2 = x1 + (width_ratio * x)
+        y2 = y1
+
+        x3 = x2
+        y3 = y1 + (height_ratio * y)
+
+        x4 = x1
+        y4 = y3
+
+        draw.line([(x1, y1), (x2, y2), (x3, y3), (x4, y4), (x1, y1)], fill=(255, 0, 0), width=3)
+        im.show()
+
+
+
+
+
+
+
+    # image_path = r'D:\devcode\ASJServer_test\static\ai\RBF474J66TLAGHW9111A\1647244844.jpg'  # 图片集地址
+    image_path = r'D:\devcode\ASJServer_test\static\ai\RBF474J66TLAGHW9111A\1647244844\1647244844_0.jpg'  # 图片集地址
+    pic_frame(image_path)
+    exit()
 
     image_dir_path = r'E:\photo\test'  # 图片集地址
     image_size = 500  # 每张小图片的大小

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff