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

python-opencv 圖像旋轉保存

系統 1807 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條評論
主站蜘蛛池模板: 精品国产看高清国产毛片 | 国产精品久久久久久久久久久威 | a久久久久一级毛片护士免费 | 欧美成人在线视频 | 欧美福利视频在线 | 一级毛片在线视频 | 国产午夜亚洲精品国产 | 精品黑人一区二区三区 | 亚洲一区二区三区播放在线 | 久久高清一区二区三区 | 天天透天天插 | 亚洲视频一区 | 亚洲精品你懂的 | 免费在线欧美 | 午夜精品成年片色多多 | 久久这里只有精品66 | 久久国产精品二国产精品 | 亚洲欧美综合国产不卡 | 精品国产自在现线看久久 | 在线第一福利视频观看 | 免费看成人国产一区二区三区 | 全毛片 | 综合激情网站 | 亚洲综合色婷婷中文字幕 | 亚洲成人免费在线观看 | 成人亚洲 | 国产成人精品视频一区 | 狠狠狠狠狠狠狠 | 成人国产欧美精品一区二区 | 奇米色888 | bbw老妇xxx | 四虎1515 | 欧美一级成人影院免费的 | 一级毛片特级毛片免费的 | 青青爽 | 国产一级特黄特色aa毛片 | 久久久全国免费视频 | 中文字幕精品一区二区三区视频 | 一级大片免费观看 | 哪里有毛片 | 毛片aa|