91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

使用python+OpenCV實現多張圖像拼接,完成拼接后進行圖像黑邊去除。里面代碼每一行都有中文注釋和附帶的實驗圖像。

資源截圖

代碼片段和文件信息

#?執行以下命令,在終端(cmd命令行)運行代碼:
#?python?image_stitching.py?--images?images/scottsdale?--output?output.png?--crop?1

#?import?the?necessary?packages
from?imutils?import?paths
import?numpy?as?np
import?argparse
import?imutils
import?cv2

#?構造參數解析器并解析參數
ap?=?argparse.ArgumentParser()
ap.add_argument(“-i“?“--images“?type=str?required=True
????????????????help=“path?to?input?directory?of?images?to?stitch“)
ap.add_argument(“-o“?“--output“?type=str?required=True
????????????????help=“path?to?the?output?image“)
ap.add_argument(“-c“?“--crop“?type=int?default=0
????????????????help=“whether?to?crop?out?largest?rectangular?region“)
args?=?vars(ap.parse_args())??#?vars函數是實現返回對象object的屬性和屬性值的字典對象

print(args)??#?{‘images‘:?‘images/scottsdale‘?‘output‘:?‘output.png‘?‘crop‘:?1}
#?匹配輸入圖像的路徑并初始化我們的圖像列表
#?rectangular_region?=?2
print(“[INFO]?loading?images...“)
#?獲取到每張待拼接圖像并排序,如[‘第一張圖片路徑‘,?第二張圖片路徑‘,第三張圖片路徑‘]
imagePaths?=?sorted(list(paths.list_images(args[“images“])))
#?print(imagePaths)
#?imagePaths?=?[‘IMG_1786-2.jpg‘
#? ??‘IMG_1787-2.jpg‘
#? ??‘IMG_1788-2.jpg‘]
images?=?[]

#?遍歷圖像路徑,加載每個路徑,然后將它們添加到我們的路徑中圖像到stich列表
for?imagePath?in?imagePaths:
????image?=?cv2.imread(imagePath)
????images.append(image)

#?初始化OpenCV的圖像sticher對象,然后執行圖像拼接
print(“[INFO]?stitching?images...“)
stitcher?=?cv2.createStitcher()?if?imutils.is_cv3()?else?cv2.Stitcher_create()
(status?stitched)?=?stitcher.stitch(images)


#?print(status?stitched)
#?如果狀態為“0”,則OpenCV成功執行圖像拼接
if?status?==?0:
????#?檢查我們是否應該從拼接圖像中裁剪出最大的矩形區域
????if?args[“crop“]?>?0:
????????#?在拼接圖像周圍創建一個10像素的黑色邊框
????????print(“[INFO]?cropping...“)
????????stitched?=?cv2.copyMakeBorder(stitched?10?10?10?10
??????????????????????????????????????cv2.BORDER_CONSTANT?(0?0?0))
????????#?cv2.imshow(‘123‘stitched)

????????#?將拼接圖像轉換為灰度
????????gray?=?cv2.cvtColor(stitched?cv2.COLOR_BGR2GRAY)
????????#?cv2.imshow(‘456‘?gray)
????????#?對灰度圖像進行閾值二值化,
????????#?這樣所有大于零的像素都設置為255(前景),而其他所有像素都保持為0(背景)
????????thresh?=?cv2.threshold(gray?0?255?cv2.THRESH_BINARY)[1]
????????#?cv2.imshow(‘789‘?thresh)
????????#?在閾值圖像中找到所有外部輪廓,然后找到?“最大?”輪廓,它將是拼接圖像的輪廓
????????#?cv2.RETR_EXTERNAL:只找外輪廓。cv2.CHAIN_APPROX_SIMPLE:輸出少量輪廓點
????????#?輸出參數1:圖像
????????#?輸出參數2:輪廓列表
????????#?輸出參數3:層級
????????cnts?=?cv2.findContours(thresh.copy()?cv2.RETR_EXTERNAL?cv2.CHAIN_APPROX_SIMPLE)
????????#?print(cnts)?#cnts包括三個數組:
????????#?print(len(cnts))

????????cnts?=?imutils.grab_contours(cnts)

????????################################
????????#?imutils.grab_contours?的源碼?:

????????????#?#?if?the?length?the?contours?tuple?returned?by?cv2.findContours
????????????#?#?is?‘2‘?then?we?are?using?either?OpenCV?v2.4?v4-beta?or
????????????#?#?v4-official
????????????#?if?len(cnts)?==?2:
????????????#?????cnts?=?cnts[0]
????????????#?#?if?the?length?of?the?contours?tuple?is?‘3‘?then?we?are?using
????????????#?#?either?OpenCV?v3?v4-pre?or?v4-alpha
????????????#?elif?len(cnts)?==?3:
????????????#?????cnts?=?cnts[1]
????????????#?#?otherwise?OpenCV?ha

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-26?11:10??圖像拼接---去除黑邊\
?????文件??????160834??2018-12-11?19:45??圖像拼接---去除黑邊\IMG_1786-2.jpg
?????文件??????155549??2018-12-11?19:45??圖像拼接---去除黑邊\IMG_1787-2.jpg
?????文件??????187918??2018-12-11?19:45??圖像拼接---去除黑邊\IMG_1788-2.jpg
?????文件????????7055??2019-03-26?11:12??圖像拼接---去除黑邊\image_stitching.py
?????目錄???????????0??2019-03-18?08:40??圖像拼接---去除黑邊\images\
?????目錄???????????0??2019-03-18?08:41??圖像拼接---去除黑邊\images\scottsdale\
?????文件??????160834??2018-12-11?19:45??圖像拼接---去除黑邊\images\scottsdale\IMG_1786-2.jpg
?????文件??????155549??2018-12-11?19:45??圖像拼接---去除黑邊\images\scottsdale\IMG_1787-2.jpg
?????文件??????187918??2018-12-11?19:45??圖像拼接---去除黑邊\images\scottsdale\IMG_1788-2.jpg
?????文件?????1059139??2018-12-11?20:10??圖像拼接---去除黑邊\output.png
?????目錄???????????0??2019-03-26?11:12??圖像拼接---去除黑邊\result\
?????文件??????234097??2019-03-25?21:37??圖像拼接---去除黑邊\result.jpg

評論

共有 條評論

相關資源