日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

使用python opencv批量对贴图进行除透明边并压缩

發布時間:2024/3/13 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用python opencv批量对贴图进行除透明边并压缩 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import glob import cv2def access_pixels(file, frame):print(frame.shape) # shape內包含三個元素:按順序為高、寬、通道數height = frame.shape[0]weight = frame.shape[1]channels = frame.shape[2]print("weight : %s, height : %s, channel : %s" % (weight, height, channels))if channels != 4:return# cv2.imwrite('crop.jpg', crop)bound_x_min = 0bound_x_max = 0bound_y_min = 0bound_y_max = 0for row in range(height): # 遍歷高exist_color = Falsefor col in range(weight): # 遍歷寬if frame[row, col, 3] == 255:exist_color = Trueif bound_y_min == 0:bound_y_min = rowif not exist_color and bound_y_min != 0 and bound_y_max == 0:bound_y_max = row - 1for col in range(weight): # 遍歷高exist_color = Falsefor row in range(height): # 遍歷寬if frame[row, col, 3] == 255:exist_color = Trueif bound_x_min == 0:bound_x_min = colif not exist_color and bound_x_min != 0 and bound_x_max == 0:bound_x_max = col - 1clip_image = frame[max(bound_y_min - 5, 0):min(bound_y_max + 5, height), max(bound_x_min - 5, 0):min(bound_x_max + 5, weight)]resized_img = cv2.resize(clip_image, (clip_image.shape[1] // 2, clip_image.shape[0] // 2))#cv2.imshow('clip_image', clip_image)cv2.imwrite(file, resized_img)def main():"""入口"""# file = "D:/alt/unlimited/project/Assets/UI/Atlas/Icon/Icon_M4A1S_Normal.png"for file in glob.glob("D:/alt/unlimited/project/Assets/UI/Atlas/Icon/*.png"):src = cv2.imread(file, cv2.IMREAD_UNCHANGED)# cv2.imshow(file, src)access_pixels(file, src)if __name__ == "__main__":main()cv2.waitKey(0)

?

總結

以上是生活随笔為你收集整理的使用python opencv批量对贴图进行除透明边并压缩的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。