prefacio
dirección del código original
github
El registro en este artículo se debe principalmente a que hay un problema con la modificación y el funcionamiento del código, por lo que comencé a construir el entorno y lo volví a modificar.
1. Crea un entorno virtual
conda create -n newCv python=3.7.0
2. Activar el entorno virtual
conda activate newCv
3. Instalar opencv y los paquetes correspondientes
3.1 Ver la versión instalable de opencv
La última versión de la instalación de opencv correspondiente se puede ver instalación de opencv
pip install opencv-python==
instalar
pip install opencv-python==3.4.2.16
realizar pruebas
3.2 Instalar el paquete correspondiente
pip install imutils
3.3 Instalar opencv-contrib-python
La solución al error
: agregue una versión del paquete contrib correspondiente
pip install opencv-contrib-python==3.4.2.16
4. Agregar lanzamiento.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["-f", "images/bryce_left_01.png", "-s", "images/bryce_right_01.png"]
}
]
}
F5 para ejecutar el código correspondiente
5. Ejecución de resultados
Resultado de costura
coincidente de característica de imagen original
6. Arreglo de proceso de código de empalme
En realidad, el método principal es bastante simple. El método principal es obtener las características correspondientes y los resultados de costura de la grapadora encapsulada.stitch
6.1 método Stitcher.stitch
def stitch(self, images, ratio=0.75, reprojThresh=4.0,
showMatches=False):
# unpack the images, then detect keypoints and extract
# local invariant descriptors from them
(imageB, imageA) = images
(kpsA, featuresA) = self.detectAndDescribe(imageA)
(kpsB, featuresB) = self.detectAndDescribe(imageB)
# match features between the two images
M = self.matchKeypoints(kpsA, kpsB,
featuresA, featuresB, ratio, reprojThresh)
# if the match is None, then there aren't enough matched
# keypoints to create a panorama
if M is None:
return None
# otherwise, apply a perspective warp to stitch the images
# together
(matches, H, status) = M
result = cv2.warpPerspective(imageA, H,
(imageA.shape[1] + imageB.shape[1], imageA.shape[0]))
result[0:imageB.shape[0], 0:imageB.shape[1]] = imageB
# check to see if the keypoint matches should be visualized
if showMatches:
vis = self.drawMatches(imageA, imageB, kpsA, kpsB, matches,
status)
# return a tuple of the stitched image and the
# visualization
return (result, vis)
# return the stitched image
return result