亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python-opencv 圖像旋轉保存

系統 2009 0

轉自:?opencv+python3.6圖像旋轉、并保持圖像像素大小不變、不被裁剪(旋轉90/180/270度)

            
              import cv2
import numpy as np
import os, shutil

def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # center
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)
    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])
    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))
    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY
    # perform the actual rotation and return the image
    return cv2.warpAffine(image, M, (nW, nH))

# 遍歷某文件夾下所有文件名,包括子文件夾下的文件名
def rotate_imagine(raw_img_path, save_img_path, angle):
    now_file_path = raw_img_path
    for dirpath, dirnames, filenames in os.walk(now_file_path):
        for filename in filenames:
            file_path = now_file_path + filename
            img = cv2.imread(file_path)
            img_rotate = rotate_bound(img, angle)
            save_file_path = save_img_path + filename
            cv2.imwrite(save_file_path, img_rotate)

if __name__=='__main__':
    for date in ['20181217', '20181218', '20181219', '20181220', '20181221']:
        for angle in [90, 180, 270]:
            raw_img_path = '/home/dl/huipu/AOI_data/factory_data_test/factory_testdata/'+ date +'/crop/aoi_crop_500_v2/JPEGImages/'
            save_img_path = '/home/dl/huipu/AOI_data/factory_data_test/factory_testdata/'+ date +'/crop/aoi_crop_500_v2/rotate/' + str(angle) + '/'
            if(os.path.exists(save_img_path)):
                shutil.rmtree(save_img_path)
            os.mkdir(save_img_path)
            rotate_imagine(raw_img_path, save_img_path, angle)









            
          

?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲四虎永久在线播放 | 国产成人禁片在线观看 | 日韩日b | 韩国高清不卡一区二区 | 免费一级欧美片片线观看 | 韩毛片| 特级黄色 | 伊人狼人综合网 | 免费看人做人爱视频拍拍拍 | 日韩美一区二区三区 | 在线精品中文字幕福利视频 | 欧美性视频一区二区三区 | 国产亚洲一欧美一区二区三区 | 成人不卡视频 | 婷婷在线视频国产综合 | 伊人久久综合谁合综合久久 | 免费播放国产性色生活片 | 97视频在线免费观看 | 男人天堂视频网 | 激情久久久久久久久久 | 久久久精品一区二区三区 | 日本一区高清视频 | 午夜精品久久久久久久90蜜桃 | 国产精品久久免费 | 欧美国产亚洲一区 | 黄色片免费在线观看视频 | 欧美草草 | 三极毛片| 成人免费国产欧美日韩你懂的 | 欧美特欧美特级一片 | 看一级特黄a大片日本片 | 特级女人十八毛片a级 | 日韩精品成人免费观看 | 视频在线一区二区三区 | 欧美777精品久久久久网 | 毛片一区二区三区 | 久久99精品国产麻豆婷婷 | 精品综合久久久久久97超人 | 久久精品亚洲 | 九九99久麻豆精品视传媒 | 日韩一区二区三区免费 |