Pure reading, please visit OPENCV using the Harris Algorithm for corner detection
Source
Kqwopencvfeaturesdemo
A corner point is an intersection of two edges or a point that has several significant edge orientations in a local neighborhood. Harris Corner Point Detection is one of the most common techniques in corner detection.
The Harris corner detector uses a sliding window on the image to calculate the brightness change.
Packaging
The Rxjava is used here. This is mainly because picture processing is a time-consuming operation that blocks threads and, in order to prevent the interface from stalling, uses Rxjava for thread switching.
/** * Harris Corner Detection * * @param bitmap image to be detected */ Public void Harris(Bitmap Bitmap) {if(NULL! = Msubscriber) Observable. Just (bitmap)//Detection Edge. Map (NewFunc1<bitmap, mat> () {@Override PublicMatPager(Bitmap Bitmap) {Mat Graymat =NewMat (); Mat cannyedges =NewMat ();//Bitmap switch to MatMat src =NewMat (Bitmap.getheight (), Bitmap.getwidth (), CVTYPE.CV_8UC4); Utils.bitmaptomat (bitmap, SRC);//Original GrayImgproc.cvtcolor (SRC, Graymat, imgproc.color_bgr2gray);///Canny edge detector detects image edgesImgproc.canny (Graymat, Cannyedges,Ten, -);returnCannyedges; } })//Harris Diagonal Detection. Map (NewFunc1<mat, bitmap> () {@Override PublicBitmapPager(Mat cannyedges) {Mat Corners =NewMat (); Mat TEMPDST =NewMat ();//Find corner pointsImgproc.cornerharris (Cannyedges, TEMPDST,2,3,0.04);//Normalization of the output of the Harris corner pointMat Tempdstnorm =NewMat (); Core.normalize (TEMPDST, Tempdstnorm,0,255, Core.norm_minmax); Core.convertscaleabs (tempdstnorm, corners);//Draw corner points on new imagesRandom r =NewRandom (); for(inti =0; I < Tempdstnorm.cols (); i++) { for(intj =0; J < Tempdstnorm.rows (); J + +) {Double[] Value = Tempdstnorm.get (j, I);if(value[0] > Max) {Core.circle (corners,NewPoint (I, J),5,NewScalar (R.nextint (255),2)); } } }//Mat turn bitmapBitmap processedimage = Bitmap.createbitmap (Corners.cols (), Corners.rows (), Bitmap.Config.ARGB_8888); Utils.mattobitmap (corners, processedimage);returnProcessedimage; }}). Subscribeon (Schedulers.io ()). Observeon (Androidschedulers.mainthread ()) . Subscribe (msubscriber);}
Use
//Image feature extraction tool classMfeaturesutil =NewFeaturesutil (NewSubscriber<bitmap> () {@Override Public void oncompleted() {//Picture processing completeDismissprogressdialog (); }@Override Public void OnError(Throwable e) {//Picture handling exceptionDismissprogressdialog (); }@Override Public void OnNext(Bitmap Bitmap) {//Get to the processed pictureMimageview.setimagebitmap (bitmap); }});//Harris Corner Point detectionMfeaturesutil.harris (Mselectimage);
OpenCV using the Harris algorithm for corner detection