A 2D fragment splicing system based on OpenCV image processing

Through the image processing and polygon splicing algorithm based on OpenCV, the problem of being unable to handle multiple splicing requirements in the existing technology is solved, and efficient and high-accuracy two-dimensional fragment splicing is achieved, which is suitable for image splicing tasks with large amounts of data.

CN114862667BActive Publication Date: 2024-10-18QINGDAO INST OF COMPUTING TECH XIDIAN UNIV +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110169905.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-04
Publication Date
2024-10-18
Estimated Expiration
2041-02-04

AI Technical Summary

Technical Problem

Existing two-dimensional fragment splicing algorithms are mainly based on theoretical research and simple operation practices. They lack integrated software systems that can adapt to various situations and cannot effectively handle the various splicing requirements of large amounts of data in practical applications.

Method used

Using an image processing method based on OpenCV, through grayscale processing, binarization processing, edge extraction and polygon fitting, combined with polygon-like splicing and fast splicing algorithms, parameters are automatically adjusted to achieve efficient image splicing.

Benefits of technology

It greatly reduces the amount of calculations under a large amount of data, improves the accuracy of splicing pictures, and can automatically select appropriate splicing methods under different splicing requirements to achieve efficient and high-accuracy image splicing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114862667B_ABST
    Figure CN114862667B_ABST
Patent Text Reader

Abstract

The present invention discloses a two-dimensional fragment splicing system and method based on OpenCV image processing. The system provides a fragment preprocessing function, including the following processing modes: (a) image grayscale processing; (b) image binarization processing; (c) image edge extraction and polygon fitting processing. The transmitted fragment data is made to reach the best splicing state as much as possible. Because different splicing algorithms need to be used to process different splicing scenes, two splicing algorithms are used: (a) polygon-like step splicing; (b) fast splicing. The system is suitable for use by individuals and small and medium-sized teams, and integrates image fragments to restore the original appearance of the image, thereby improving the research efficiency of individuals or teams on fragments. This system realizes the rapid transplantation of the system, making it a convenient and mobile system that is simple to operate and easy to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computer vision, in particular to a two-dimensional fragment splicing method based on OpenCV image processing. Background Art

[0002] At present, there are many studies in this area in the industry:

[0003] (a) A paper fragment splicing algorithm based on shape matching. This type of algorithm mainly observes the contour and finds the fragments that can be well spliced ​​onto the contour, thereby achieving the purpose of fragment matching and splicing;

[0004] (b) Based on local matching of contour angle features, this algorithm captures the local angle matching of fragments and finds the form of global fragment matching, thereby achieving the purpose of matching and splicing multiple fragments;

[0005] (c) Global matching of breadth-first search. This algorithm focuses on how to splice fragments. When we successfully find matching fragments and matching positions, we can use an algorithm to restore the fragments on a computer.

[0006] The above algorithm is a theoretical study based on the matching and splicing of fragment shapes and edge features.

[0007] Of course, there are also content-based splicing algorithms, such as:

[0008] (a) Vector matching of edge content. This algorithm grasps the idea that fragments can be matched because the edge content is often consistent. It uses a matching method based on edge grayscale information to achieve matching and splicing of fragments.

[0009] (b) Automatic stitching of color image fragments. This algorithm mainly converts RGB images into HSV images from another perspective of RGB images. The author believes that the effect obtained by HSV is often better than that obtained by grayscale information, so this method is used to achieve matching stitching.

[0010] The above is a theoretical study on matching and splicing based on fragment edge content.

[0011] In summary, the problems with existing research technologies are: the several splicing algorithms mentioned above can be said to be the better two-dimensional fragment splicing ideas so far, and are also relatively novel algorithm research. However, most of these studies are mainly based on theory and simple operational feasibility. There are many related research results, and the implementation method is only an experiment, or a splicing algorithm system dedicated to a certain fragment. There is no real software system that integrates multiple fragment splicing algorithms and adapts to various situations, and it is not clearly mentioned in related research papers. Summary of the invention

[0012] In view of the problems existing in the prior art, the present invention provides a two-dimensional fragment splicing method based on OpenCV image processing.

[0013] The present method is conceived as follows: a two-dimensional fragment splicing method based on OpenCV image processing. The two-dimensional fragment splicing method uses OpenCV to perform image grayscale processing, binarization processing, image edge extraction and polygon fitting processing. The transmitted fragment data is made to achieve the best splicing state as much as possible. In order to use different splicing algorithms to handle different splicing scenarios, two splicing algorithms are used: (a) polygon-like step splicing; (b) fast splicing.

[0014] A two-dimensional fragment splicing method comprises the following steps:

[0015] Step 1: The upload module collects a large number of image fragments as metadata for the 2D fragment stitching system.

[0016] Step 2: The pre-processing module grayscales all fragments

[0017] Step 3: The preprocessing module performs binarization on all fragments.

[0018] Step 4: The preprocessing module performs edge search on the binary image. The function used is OpenCV's findContours. The essence of this is to perform topological analysis on the binary image to obtain the outer boundary, hole boundary, and their hierarchical relationship.

[0019] Step 5: The preprocessing module polygonizes the obtained edge information fragments to obtain the corner points of the fragments.

[0020] Step 6: The corner points obtained in step 5 and the edge information obtained in step 4 are processed for each fragment to obtain an edge grayscale sequence and an edge length sequence.

[0021] Step 7: The stitching selection module selects polygonal stitching or fast stitching algorithm according to different scenarios.

[0022] Step 8: If the splicing is done manually, you can re-splice other fragments, press the manually spliced ​​secondary fragments into the fragment stack, and repeat steps 1 to 7.

[0023] Furthermore, the upload module first needs to collect a large number of two-dimensional fragments that need to be spliced. This module mainly provides the system with the image fragments to be spliced ​​and uploads them to the backend storage for subsequent operations.

[0024] Furthermore, the preprocessing module sets parameters for the image fragments uploaded to the background, such as the calculation of parameters such as boundary length and grayscale value for polygonal stitching, and parameters such as corner angle for fast stitching, and previews the effect after the set parameters. According to the presentation of the effect, the parameters are adjusted to obtain better image preprocessing parameters, which provides a guarantee for obtaining the most correct answer for the subsequent stitching results.

[0025] Furthermore, the splicing selection module includes a polygon-like splicing and a fast splicing algorithm, and the specific steps of the polygon-like splicing algorithm include:

[0026] (1) Randomly select an image from the fragment sequence (pop it out from the fragment sequence), and perform length matching on each edge of each remaining fragment, using the absolute value of the difference in line segment distances to obtain a matching information sequence (this sequence mainly stores the information of the matching edges and the matching values, using a data structure similar to a dictionary tree).

[0027] (2) Select the smallest matching information from the matching information sequence in (1).

[0028] (3) When there is only one minimum matching information, the two fragments are directly spliced ​​according to the splicing position of the records in the sequence (at the same time, the fragment to be spliced ​​is popped out of the fragment sequence), and the spliced ​​result graph is pushed to the end of the fragment sequence.

[0029] (4) When there are multiple minimum matching information, perform grayscale value matching detection on them respectively with the edge of the minimum matching information to obtain the one with the most consistent value, that is, the smallest one. The two fragments are spliced ​​according to the recorded matching parts (at the same time, the fragment to be spliced ​​is popped out of the fragment sequence), and the spliced ​​result image is pushed into the end of the fragment sequence.

[0030] (5) If the number of fragment sequences is equal to 1, the splicing is complete and the result image is output. If it is greater than 1, the steps of the image splicing stage are repeated.

[0031] The specific steps of the fast splicing algorithm include:

[0032] A matches each pair of images in turn, using the LCS dynamic programming algorithm. Obtain and save the matching coefficient and matching position.

[0033] B can obtain an undirected graph through (1), in which each vertex represents the contour information of an image, and the edge connecting the vertices represents the matching coefficient of the two fragment images.

[0034] C generates a tree with the largest sum of matching coefficients from the graph (actually the minimum spanning tree algorithm), implements it using a priority queue and BFS (breadth-first search), and then records each edge of the tree.

[0035] D traverses each edge and, according to the previously recorded contour matching position, stitches the two vertices corresponding to the edge, i.e., the fragmented images, in turn, and finally obtains a complete stitched image.

[0036] Usually irregular shapes can be fitted into polygons, and polygons have corners. Whether the fragments can be spliced ​​together often depends on the matching between the corners. When the angle of the vector formed by a vertex is concave 45°, the one that can match it is convex 45°. When this happens, choose to use the fast splicing method, otherwise use the polygon-like splicing algorithm.

[0037] In summary, the advantages and positive effects of the present invention are as follows: the steps of the present invention are simple, and under a very large amount of data, compared with the prior art, the method of the present invention can greatly reduce the amount of calculation; on the other hand, the final stitched picture accuracy reaches a high level, and the two-dimensional fragment stitching method based on OpenCV proposed by the present invention does not require manual participation in the image processing process. Through the dynamic adjustment of the system itself, the picture accuracy of each stitching method can reach a high level. When there are different stitching requirements, different stitching methods can be used. For data with a large amount of data fragments, the prior art cannot use multiple stitching methods and preprocessing for image stitching at the same time. The present invention can achieve the highest accuracy and the stitching effect of the largest amount of data in a very short time. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a flow chart of a two-dimensional fragment splicing system and method based on OpenCV image processing.

[0039] Figure 2 It is an overall functional module diagram of a two-dimensional fragment splicing system and method based on OpenCV image processing.

[0040] Figure 3 Specific splicing diagram. DETAILED DESCRIPTION

[0041] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0042] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0043] according to Figure 1 and Figure 2 As shown, the preprocessing module grayscales all fragments; binarizes all fragments. This program can use the threshold method of OpenCV to implement two binarization methods: one is to convert the current grayscale value to 255 when it is greater than the set threshold, and to 0 when it is not greater than the threshold; the other is to convert the current grayscale value to 0 when it is greater than the threshold, and to 255 when it is greater than the threshold; the binary image is edge searched, and the function used is findContours of OpenCV, which is essentially a topological analysis of the binary image to obtain the outer boundary, hole boundary and their hierarchical relationship. The obtained edge information fragments are polygonally approximated to obtain the corner points of the fragments. The function used is approxPolyDP of OpenCV. This algorithm approximates the curve as a series of points and reduces the number of points. Through the obtained corner points and edge information, each fragment is processed to obtain the edge grayscale sequence and edge length sequence.

[0044] The splicing selection module selects a polygon-like splicing algorithm or a fast splicing algorithm according to the fragment information obtained in the preprocessing stage. Manual splicing can be performed, and multiple manually spliced ​​fragments are reassembled into a new larger fragment and re-preprocessed.

[0045] A two-dimensional fragment splicing method comprises the following steps:

[0046] Step 1: The upload module collects a large number of image fragments as metadata for the 2D fragment stitching system.

[0047] Step 2: The pre-processing module grayscales all fragments

[0048] Step 3: The preprocessing module performs binarization on all fragments.

[0049] Step 4: The preprocessing module performs edge search on the binary image. The function used is OpenCV's findContours. The essence of this is to perform topological analysis on the binary image to obtain the outer boundary, hole boundary, and their hierarchical relationship.

[0050] Step 5: The preprocessing module polygonizes the obtained edge information fragments to obtain the corner points of the fragments.

[0051] Step 6: The corner points obtained in step 5 and the edge information obtained in step 4 are processed for each fragment to obtain an edge grayscale sequence and an edge length sequence.

[0052] Step 7: The stitching selection module selects polygonal stitching or fast stitching algorithm according to different scenarios.

[0053] Step 8: If the splicing is done manually, you can re-splice other fragments, press the manually spliced ​​secondary fragments into the fragment stack, and repeat steps 1 to 7.

[0054] Furthermore, the upload module first needs to collect a large number of two-dimensional fragments that need to be spliced. This module mainly provides the system with the image fragments to be spliced ​​and uploads them to the backend storage for subsequent operations.

[0055] Furthermore, the preprocessing module sets parameters for the image fragments uploaded to the background, such as the boundary length and grayscale value required for polygonal stitching, and the corner angle required for fast stitching, and previews the effect after the set parameters. According to the presentation of the effect, the parameters are adjusted to obtain better image preprocessing parameters, which provides a guarantee for obtaining the most correct answer for the subsequent stitching results.

[0056] Furthermore, the splicing selection module includes a polygon-like splicing and a fast splicing algorithm, and the specific steps of the polygon-like splicing algorithm include:

[0057] (1) Randomly select an image from the fragment sequence (pop it out from the fragment sequence), and perform length matching on each edge of each remaining fragment, using the absolute value of the difference in line segment distances to obtain a matching information sequence (this sequence mainly stores the information of the matching edges and the matching values, using a data structure similar to a dictionary tree).

[0058] (2) Select the smallest matching information from the matching information sequence in (1).

[0059] (3) When there is only one minimum matching information, the two fragments are directly spliced ​​according to the splicing position of the records in the sequence (at the same time, the fragment to be spliced ​​is popped out of the fragment sequence), and the spliced ​​result graph is pushed to the end of the fragment sequence.

[0060] (4) When there are multiple minimum matching information, perform grayscale value matching detection on them respectively with the edge of the minimum matching information to obtain the one with the most consistent value, that is, the smallest one. The two fragments are spliced ​​according to the recorded matching parts (at the same time, the fragment to be spliced ​​is popped out of the fragment sequence), and the spliced ​​result image is pushed into the end of the fragment sequence.

[0061] (5) If the number of fragment sequences is equal to 1, the splicing is complete and the result image is output. If it is greater than 1, the steps of the image splicing stage are repeated.

[0062] The specific steps of the fast splicing algorithm include:

[0063] A matches each pair of images in turn, using the LCS dynamic programming algorithm. Obtain and save the matching coefficient and matching position.

[0064] B can obtain an undirected graph through A, in which each vertex represents the contour information of an image, and the edge connecting the vertices represents the matching coefficient of the two fragment images.

[0065] C generates a tree with the largest sum of matching coefficients from the graph (actually the minimum spanning tree algorithm), implements it using a priority queue and BFS (breadth-first search), and then records each edge of the tree.

[0066] D traverses each edge and, according to the previously recorded contour matching position, stitches the two vertices corresponding to the edge, i.e., the fragmented images, in turn, and finally obtains a complete stitched image.

[0067] like Figure 3 As shown in the figure, irregular shapes can usually be fitted into polygons, and polygons have corners. Whether the fragments can be spliced ​​together often depends on the matching between the corners. When the angle of the vector formed by a vertex is concave 45°, the one that can match it is convex 45°. When this happens, choose to use the fast splicing method, otherwise use the polygon-like splicing algorithm.

Claims

1. A two-dimensional fragment splicing system based on OpenCV image processing, including an uploading module, a preprocessing module, and a splicing selection module, characterized in that: The upload module first needs to collect a large number of two-dimensional fragments that need to be spliced. This module mainly provides the system with the image fragments to be spliced ​​and uploads them to the backend storage for subsequent operations; Preprocessing module: In this module, the image fragments uploaded to the background are set with parameters, which are determined by the different stitching algorithms provided, and the effect after the set parameters are previewed. According to the presentation of the effect, the parameters are adjusted to obtain better image preprocessing parameters, which provides a guarantee for obtaining the most correct answer for the subsequent stitching results; The splicing selection module uses an algorithm to integrate the fragments into a complete restoration image based on the parameters provided in the previous step; The two-dimensional fragment splicing method comprises the following steps: Step 1: The upload module collects a large number of image fragments as metadata for the 2D fragment stitching system; Step 2: The pre-processing module performs grayscale processing on all fragments; Step 3: The preprocessing module performs binarization on all fragments; When the current grayscale value is greater than the set threshold, it is changed to 255, and if it is not greater than, it is changed to 0; or when the current grayscale value is greater than the set threshold, it is changed to 0, and if it is not greater than, it is changed to 255; Step 4: The preprocessing module performs edge search on the binary image. The function used is OpenCV's findContours. The essence of this is to perform topological analysis on the binary image to obtain the outer boundary, hole boundary, and their hierarchical relationship. Step 5: The preprocessing module performs polygon integration on the edge information fragments to obtain the corner points of the fragments. The function used is approxPolyDP of OpenCV. Step 6: The corner points obtained in step 5 and the edge information obtained in step 4 are processed for each fragment to obtain an edge grayscale sequence and an edge length sequence; Step 7: The stitching selection module selects polygonal stitching or fast stitching algorithm according to different scenarios; The specific steps of the polygon-like splicing algorithm include: (1) Randomly select a picture from the fragment sequence, that is, pop it out of the fragment sequence, and perform length matching on each edge of each remaining fragment, using the absolute value of the difference in line segment distance to obtain a matching information sequence. This sequence mainly stores the information of the matching edges and the matching values; (2) Select the smallest matching information from the matching information sequence in (1); (3) When there is only one minimum matching information, the two fragments are spliced ​​directly according to the splicing position of the records in the sequence, and the fragment to be spliced ​​is popped out of the fragment sequence, and the spliced ​​result image is pushed to the end of the fragment sequence; (4) When there are multiple minimum matching information, grayscale value matching detection is performed on them respectively with the edge of the minimum matching information to obtain the one with the most consistent value, that is, the smallest one. The two fragments are spliced ​​according to the recorded matching parts, that is, the fragment to be spliced ​​is ejected from the fragment sequence at the same time, and the spliced ​​result image is pressed into the end of the fragment sequence; (5) Determine the number of fragment sequences. If it is equal to 1, the splicing is complete and the result image is output. If it is greater than 1, repeat the steps of the image splicing stage. The processing object is a fragment with irregular edge contours. The algorithm used is a fast splicing algorithm. This algorithm first performs basic image processing operations on all the original fragments provided: grayscale transformation, binarization, edge search, polygon approximation, and the polygon corner points and their corresponding corner point transformation sequences are obtained by using the corner point method between calculation vectors. Finally, the corner point transformation sequence is subjected to LCS (Longest Common Substring Matching). The specific steps of the fast splicing algorithm include: A matches each pair of images in turn, using the LCS dynamic programming algorithm to obtain and save the matching coefficients and matching positions; B can obtain an undirected graph through A, where each vertex represents the contour information of an image, and the edge connecting the vertices represents the matching coefficient of the two fragment images; C generates a tree with the largest sum of matching coefficients from the graph, using priority queue and BFS breadth-first search, and then records each edge of the tree; D traverses each edge and, according to the previously recorded contour matching position, stitches the two vertices corresponding to the edge, i.e., the fragmented images, in turn, and finally obtains a complete stitched image; Step 8: If the splicing is done manually, you can re-splice other fragments, press the manually spliced ​​secondary fragments into the fragment stack, and repeat steps 1 to 7; The preprocessing module sets parameters for the image fragments uploaded to the background, including the boundary length and grayscale value parameters required for polygonal stitching, corner angle parameters required for fast stitching, and previews the effect after the set parameters.

Citation Information

Patent Citations

  • Multi-splicing mode system and method of panoramic camera

    CN107529017A

  • Cosine similarity adaptive algorithm-based image splicing method and device

    CN108109108A