久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

python圖片剪裁代碼(圖片按四個點坐標剪裁)

瀏覽:3日期:2022-08-03 08:32:21

用了兩種方法保存圖片,opencv和Image,實踐證明opencv非常快

from PIL import Imageimport osimport cv2import timeimport matplotlib.pyplot as pltdef label2picture(cropImg,framenum,tracker): pathnew ='E:img2' # cv2.imshow('image', cropImg) # cv2.waitKey(1) if (os.path.exists(pathnew + tracker)): cv2.imwrite(pathnew + tracker+’’+framenum + ’.jpg’, cropImg,[int(cv2.IMWRITE_JPEG_QUALITY), 100]) else: os.makedirs(pathnew + tracker) cv2.imwrite(pathnew + tracker+’’+framenum + ’.jpg’, cropImg,[int(cv2.IMWRITE_JPEG_QUALITY), 100]) f = open('E:hypotheses.txt','r')lines = f.readlines()for line in lines: li = line.split(’,’) print(li[0],li[1],li[2],li[3],li[4],li[5]) filename = li[0]+’.jpg’ img = cv2.imread('E:DeeCampimg1' + filename) crop_img = img[int(li[3][:-3]):(int(li[3][:-3]) + int(li[5][:-3])),int(li[2][:-3]):(int(li[2][:-3]) + int(li[4][:-3]))] # print(int(li[2][:-3]),int(li[3][:-3]),int(li[4][:-3]),int(li[5][:-3])) label2picture(crop_img, li[0], li[1])# ## x,y,w,h = 87,158,109,222# img = cv2.imread('E:DeeCampimg11606.jpg')# # print(img.shape)# crop = img[y:(h+y),x:(w+x)]# cv2.imshow('image', crop)# cv2.waitKey(0)# img = Image.open('E:DeeCampimg13217.jpg')## cropImg = img.crop((x,y,x+w,y+h))# cropImg.show() # img = Image.open('E:deep_sort-masterMOT16traintry1img1'+filename) # print(int(li[2][:-3]),(int(li[2][:-3])+int(li[4][:-3])), int(li[3][:-3]),(int(li[3][:-3])+int(li[5][:-3]))) # #裁切圖片 # # cropImg = img.crop(region) # # cropImg.show() # framenum ,tracker= li[0],li[1] # pathnew = ’E:DeeCampdeecamp項目deep_sort-mastercrop_picture’ # if (os.path.exists(pathnew + tracker)): # # 保存裁切后的圖片 # plt.imshow(cropImg) # plt.savefig(pathnew + tracker+’’+framenum + ’.jpg’) # else: # os.makedirs(pathnew + tracker) # plt.imshow(cropImg) # plt.savefig(pathnew + tracker+’’+framenum + ’.jpg’)

補充知識:python實現固定區域截圖,實現錄屏截圖

1、實現固定區域截圖及保存

如果不設置區域默認是全屏保存

from PIL import ImageGrab # 參數說明# 第一個參數 開始截圖的x坐標# 第二個參數 開始截圖的y坐標# 第三個參數 結束截圖的x坐標# 第四個參數 結束截圖的y坐標bbox = (760, 0, 1160, 1080)im = ImageGrab.grab(bbox) # 參數 保存截圖文件的路徑im.save(’zy.png’)

2、實現屏幕的視頻錄制

可以用上面程序的bbox設置一下錄屏區域

from time import sleepfrom PIL import ImageGrabm=int(input('輸入錄屏幾分鐘:'))m=m*60n=1while n<m: sleep(0.02) im=ImageGrab.grab() local=(r'%s.jpg'%(n)) im.save(local,’jpeg’) n=n+1

以上這篇python圖片剪裁代碼(圖片按四個點坐標剪裁)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 临海市| 特克斯县| 景德镇市| 遂昌县| 英吉沙县| 克拉玛依市| 通渭县| 将乐县| 福鼎市| 铁力市| 乌鲁木齐市| 凤山市| 阳曲县| 阿瓦提县| 隆安县| 尼木县| 综艺| 万州区| 蕲春县| 巩留县| 班玛县| 高密市| 宿州市| 北流市| 锡林浩特市| 凌云县| 扎赉特旗| 鄯善县| 阜阳市| 宝清县| 辰溪县| 缙云县| 永丰县| 黄石市| 中阳县| 龙南县| 古交市| 龙口市| 武鸣县| 武强县| 十堰市|