免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

python如何在人物圖中添加水印

這篇文章給大家分享的是有關python如何在人物圖中添加水印的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

為蘭西等地區用戶提供了全套網頁設計制作服務,及蘭西網站建設行業解決方案。主營業務為成都網站設計、成都網站建設、外貿網站建設、蘭西網站設計,以傳統方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業、用心的態度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

python有哪些常用庫

python常用的庫:1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。

1、主要流程

素材準備

人臉檢測與人臉關鍵點檢測

調整大小,添加帽子

2、步驟

(1)用dlib的正臉檢測器進行人臉檢測,用dlib提供的模型提取人臉的五個關鍵點:

# dlib人臉關鍵點檢測器
      predictor_path = "shape_predictor_5_face_landmarks.dat"
      predictor = dlib.shape_predictor(predictor_path)  
 
      # dlib正臉檢測器
      detector = dlib.get_frontal_face_detector()
 
      # 正臉檢測
      dets = detector(img, 1)
 
      # 如果檢測到人臉
      if len(dets)>0:  
          for d in dets:
              x,y,w,h = d.left(),d.top(), d.right()-d.left(), d.bottom()-d.top()
              # x,y,w,h = faceRect  
              cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2,8,0)
 
              # 關鍵點檢測,5個關鍵點
              shape = predictor(img, d)
              for point in shape.parts():
                  cv2.circle(img,(point.x,point.y),3,color=(0,255,0))
 
              cv2.imshow("image",img)
              cv2.waitKey()

(2)調整帽子的大小。

選擇兩個眼角點,找到中心作為放置帽子的X方向的參考坐標,Y方向的坐標用面框上線的Y坐標表示。然后我們根據檢測到的人臉大小調整帽子的大小,讓帽子的大小合適。

# 選取左右眼眼角的點
              point1 = shape.part(0)
              point2 = shape.part(2)
 
              # 求兩點中心
              eyes_center = ((point1.x+point2.x)//2,(point1.y+point2.y)//2)
 
              # cv2.circle(img,eyes_center,3,color=(0,255,0))  
              # cv2.imshow("image",img)
              # cv2.waitKey()
 
              #  根據人臉大小調整帽子大小
              factor = 1.5
              resized_hat_h = int(round(rgb_hat.shape[0]*w/rgb_hat.shape[1]*factor))
              resized_hat_w = int(round(rgb_hat.shape[1]*w/rgb_hat.shape[1]*factor))
 
              if resized_hat_h > y:
                  resized_hat_h = y-1
 
              # 根據人臉大小調整帽子大小
              resized_hat = cv2.resize(rgb_hat,(resized_hat_w,resized_hat_h))

(3)添加小圖標

當然有些同學的頭像不是人物或不能準確的識別無關,所有添加了標識。(即在右下添加小圖標)。

小圖標避免單調,是從圖標中隨機選擇一個:

圖標位置也可以根據愛好調整大小和位置

layer.paste(logo, (img.size[0] - logo.size[0], img.size[1]-logo.size[1]))

代碼如下:

# 水印圖片
    num = random.randint(1, 5)
    logo = Image.open("img_icon/santa_" + str(num) + ".png")
    img = Image.open(imgPath)
    print(img.size, logo.size)
    # 圖層
    layer = Image.new("RGBA", img.size, (255, 255, 255, 0))
    layer.paste(logo, (img.size[0] - logo.size[0], img.size[1]-logo.size[1]))
    # 覆蓋
    img_after = Image.composite(layer, img, layer)
    # img_after.show()
    img_after.save(outImgePath)

感謝各位的閱讀!關于“python如何在人物圖中添加水印”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

本文名稱:python如何在人物圖中添加水印
文章URL:http://newbst.com/article36/jhdhsg.html

成都網站建設公司_創新互聯,為您提供外貿建站微信公眾號云服務器網站收錄網站策劃移動網站建設

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網站建設