OpenCV's full name is: Open Source Computer Vision Library. It is an open source Cross-platform Computer Vision Library, which realizes many common algorithms in image processing and computer vision.
Its application fields are: 1, human-machine interaction 2, object Recognition 3, image segmentation 4, face recognition 5, action recognition 6, movement tracking 7, Robot 8, motion Analysis 9, machine Vision 10, structure Analysis 11, car safety driving
2, using OpenCV for picture stitching
Here's a sample example that shows how to use OpenCV to stitch multiple photos into a panoramic view. Note: There should be overlap between photos and photos, so that the OpenCV can be analyzed and identified to achieve automatic stitching.
(1) Here are some of the original photos taken
(2) The following is a mosaic of photos
(1) First download the latest OPENCV frame: Opencv2.framework.zip. and add it to your project.
(2) Download the third party's Objective-c encapsulation class: Opencvswiftstitch
Because we need to use OPENCV, Swift cannot call C + + directly. So it is necessary to use objective-c as the middle layer and let Swift invoke OpenCV through Objective-c.
Fortunately, GitHub has been provided with the relevant packaging classes, we directly import the following files to the project.
(3) Remember to add CVWrapper.h to the bridge header file Bridge.h
#import "CVWrapper.h"
(4) The use of the following is very simple, the uiimage to Cvwrapper on it
Import Uikit
Class Viewcontroller:uiviewcontroller {
@IBOutlet weak var imageview:uiimageview!
@IBOutlet weak var spinner:uiactivityindicatorview!
Override Func Viewdidload () {
Super.viewdidload ()
}
Override func Viewdidappear (Animated:bool) {
Super.viewdidappear (animated)
Stitch ()
}
Func stitch () {
Because the picture splicing is time-consuming, displays the circular progress bar
Self.spinner.startAnimating ()
Stitching pictures in the background queue
Dispatch_async (Dispatch_get_global_queue (dispatch_queue_priority_default, 0)) {
Let Image1 = UIImage (named: "Img_4247.jpg")
Let Image2 = UIImage (named: "Img_4248.jpg")
Let Image3 = UIImage (named: "Img_4249.jpg")
Let Image4 = UIImage (named: "Img_4250.jpg")
Let imagearray:[uiimage!] = [Image1,image2,image3,image4]
Let Stitchedimage:uiimage = Cvwrapper.processwitharray (Imagearray) as UIImage
Self.imageView.image = Stitchedimage
Stop Loop progress bar effect
Self.spinner.stopAnimating ()
}
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}