stitching panoramic images c++ c opencv image-stitching opencv-stitching

c++ - panoramic - OpenCV-Stitching Images from a grid of images



panoramic images python (5)

He encontrado algunos ejemplos básicos de trabajo en costura a través de OpenCV para imágenes panorámicas. También he encontrado documentación útil en los documentos de la API , pero no puedo descubrir cómo acelerar el procesamiento al proporcionar información adicional.

En mi caso, genero un conjunto de imágenes en una cuadrícula de marcos individuales de 20x20, para un total de 400 imágenes que se unen en una sola grande. Esto lleva una enorme cantidad de tiempo en una PC moderna, por lo que probablemente tomaría horas en un panel de desarrolladores.

¿Hay alguna forma de decirle a la instancia de OpenCV información sobre las imágenes, como que yo sepa de antemano el posicionamiento relativo de todas las imágenes tal como aparecerían en una cuadrícula? Las únicas llamadas a la API que veo hasta ahora es simplemente agregar todas las imágenes indiscriminadamente a una cola a través de vImg.push_back() .

Referencias

  1. Puntadas. Creación de imágenes: documentación de la API de OpenCV , consultada 2014-02-26, <http://docs.opencv.org/modules/stitching/doc/stitching.html>
  2. Ejemplo de OpenCV Stitching (clase Stitcher, Panorama) , consultado 2014-02-26, <http://feelmare.blogspot.ca/2013/11/opencv-stitching-example-stitcher-class.html>
  3. Panorama - Imagen de costura en OpenCV , acceso 2014-02-26, <http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/>

Considere habilitar el uso de GPU en Opencv Stitcher:

bool try_use_gpu = true; Stitcher myStitcher = Stitcher::createDefault(try_use_gpu); Stitcher::Status status = myStitcher.stitch(Imgs, pano);


Por lo que sé, no hay medios para proporcionar datos adicionales al motor de OpenCV más allá de simplemente darle una lista de imágenes. Aunque hace un trabajo bastante bueno por sí solo. Revisaría algunos de los códigos de ejemplo y probaría cuánto demora cada operación de costura. De mis experimentos con reconstrucciones panorámicas 4x6, 4x8, ..., 4x20, el tiempo de CPU requerido parece aumentar con el número de imágenes superpuestas. Me imagino que su caso requeriría al menos un minuto para calcular en una máquina moderna.

Fuente: https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/stitching.cpp?rev=6682

1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 // Third party copyrights are property of their respective owners. 16 // 17 // Redistribution and use in source and binary forms, with or without modification, 18 // are permitted provided that the following conditions are met: 19 // 20 // * Redistribution''s of source code must retain the above copyright notice, 21 // this list of conditions and the following disclaimer. 22 // 23 // * Redistribution''s in binary form must reproduce the above copyright notice, 24 // this list of conditions and the following disclaimer in the documentation 25 // and/or other materials provided with the distribution. 26 // 27 // * The name of the copyright holders may not be used to endorse or promote products 28 // derived from this software without specific prior written permission. 29 // 30 // This software is provided by the copyright holders and contributors "as is" and 31 // any express or implied warranties, including, but not limited to, the implied 32 // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 // In no event shall the Intel Corporation or contributors be liable for any direct, 34 // indirect, incidental, special, exemplary, or consequential damages 35 // (including, but not limited to, procurement of substitute goods or services; 36 // loss of use, data, or profits; or business interruption) however caused 37 // and on any theory of liability, whether in contract, strict liability, 38 // or tort (including negligence or otherwise) arising in any way out of 39 // the use of this software, even if advised of the possibility of such damage. 40 // 41 //M*/ 42 43 // We follow to these papers: 44 // 1) Construction of panoramic mosaics with global and local alignment. 45 // Heung-Yeung Shum and Richard Szeliski. 2000. 46 // 2) Eliminating Ghosting and Exposure Artifacts in Image Mosaics. 47 // Matthew Uyttendaele, Ashley Eden and Richard Szeliski. 2001. 48 // 3) Automatic Panoramic Image Stitching using Invariant Features. 49 // Matthew Brown and David G. Lowe. 2007. 50 51 #include <iostream> 52 #include <fstream> 53 #include "opencv2/highgui/highgui.hpp" 54 #include "opencv2/stitching/stitcher.hpp" 55 56 using namespace std; 57 using namespace cv; 58 59 void printUsage() 60 { 61 cout << 62 "Rotation model images stitcher./n/n" 63 "stitching img1 img2 [...imgN]/n/n" 64 "Flags:/n" 65 " --try_use_gpu (yes|no)/n" 66 " Try to use GPU. The default value is ''no''. All default values/n" 67 " are for CPU mode./n" 68 " --output <result_img>/n" 69 " The default is ''result.jpg''./n"; 70 } 71 72 bool try_use_gpu = false; 73 vector<Mat> imgs; 74 string result_name = "result.jpg"; 75 76 int parseCmdArgs(int argc, char** argv) 77 { 78 if (argc == 1) 79 { 80 printUsage(); 81 return -1; 82 } 83 for (int i = 1; i < argc; ++i) 84 { 85 if (string(argv[i]) == "--help" || string(argv[i]) == "/?") 86 { 87 printUsage(); 88 return -1; 89 } 90 else if (string(argv[i]) == "--try_gpu") 91 { 92 if (string(argv[i + 1]) == "no") 93 try_use_gpu = false; 94 else if (string(argv[i + 1]) == "yes") 95 try_use_gpu = true; 96 else 97 { 98 cout << "Bad --try_use_gpu flag value/n"; 99 return -1; 100 } 101 i++; 102 } 103 else if (string(argv[i]) == "--output") 104 { 105 result_name = argv[i + 1]; 106 i++; 107 } 108 else 109 { 110 Mat img = imread(argv[i]); 111 if (img.empty()) 112 { 113 cout << "Can''t read image ''" << argv[i] << "''/n"; 114 return -1; 115 } 116 imgs.push_back(img); 117 } 118 } 119 return 0; 120 } 121 122 123 int main(int argc, char* argv[]) 124 { 125 int retval = parseCmdArgs(argc, argv); 126 if (retval) return -1; 127 128 Mat pano; 129 Stitcher stitcher = Stitcher::createDefault(try_use_gpu); 130 Stitcher::Status status = stitcher.stitch(imgs, pano); 131 132 if (status != Stitcher::OK) 133 { 134 cout << "Can''t stitch images, error code = " << status << endl; 135 return -1; 136 } 137 138 imwrite(result_name, pano); 139 return 0; 140 } 141 142


Si conoce las posiciones relativas de las imágenes, parece que podría dividir el problema en subproblemas y posiblemente reducir la carga computacional al acercarse a él con el conocimiento de la subestructura del problema. Básicamente, divida el conjunto de imágenes en grupos de 4 imágenes adyacentes, procese los cuadros y luego procese las imágenes resultantes con la misma idea hasta que haya llegado a su panorama. Dicho esto, solo recientemente he empezado a jugar con este conjunto de herramientas de Opencv. Sé que es una idea bastante simple, pero podría ser útil para alguien.



Trabajé un poco con la tubería de costura y, aunque no me considero un experto en el campo, obtuve un mejor rendimiento (y mejores resultados también) ajustando cada paso de la tubería por separado. Como puede ver en la imagen, la clase de costura no es más que una envoltura de esta tubería:

Algunas partes interesantes que puede ajustar son los pasos de cambio de tamaño (llega un punto en el que más resolución simplemente significa más tiempo de cómputo y características más inexactas), el proceso de coincidencia y (aunque esto es solo una conjetura) que proporciona buenos parámetros de cámara en lugar de realizar una Estimacion. Esto implica obtener los parámetros de la cámara antes de realizar la costura, pero no es realmente difícil. Aquí tiene alguna referencia: Calibración de cámara OpenCV y Reconstrucción 3D .

Nuevamente: no soy un experto, ¡esto se basa en mi experiencia como pasante haciendo algunos experimentos con la biblioteca!