Java?OpenCV圖像處理之SIFT角點(diǎn)檢測詳解
介紹
在某些情況下對圖像進(jìn)行縮放后,角點(diǎn)信息可能會丟失,這時候Harri便不能檢測到所有的角點(diǎn)。SIFT(scale-invariant feature transform) 剛好克服了這個問題,對圖像特征的檢測,盡量不受圖像尺寸變化的影響.SIFT并不直接檢測關(guān)鍵點(diǎn)。
其中關(guān)鍵點(diǎn)的檢測是由DOG(Difference of Gaussians)檢測完成的(DOG是通過不同的高斯濾波器對同一張圖像進(jìn)行處理,來得到關(guān)鍵點(diǎn)的)。SIFT僅通過特征向量來描述特征點(diǎn)周圍的像素情況。
示例代碼
package com.xu.opencv; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfKeyPoint; import org.opencv.core.Scalar; import org.opencv.features2d.Features2d; import org.opencv.features2d.SIFT; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; /** * @Title: Image.java * @Description: OpenCV-4.0.0 測試文件 * @Package com.xu.Image * @author: hyacinth * @date: 2022年2月18日12點(diǎn)20分 * @version: V-1.0.0 * @Copyright: 2019 hyacinth */ public class Image { static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { sift(); } /** * OpenCV-4.1.0 SIFT 角點(diǎn)檢測 * * @return void * @Author: hyacinth * @Title: harris * @Description: TODO * @date: 2022年2月18日12點(diǎn)32分 */ public static void sift() { Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\1.png"); Mat gray = new Mat(); Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY); SIFT sift = SIFT.create(8000); MatOfKeyPoint point = new MatOfKeyPoint(); sift.detect(gray, point); Features2d.drawKeypoints(src, point, src, new Scalar(0, 0, 255), Features2d.DrawMatchesFlags_DRAW_RICH_KEYPOINTS); HighGui.imshow("SIFT 角點(diǎn)檢測", src); HighGui.waitKey(0); } }
效果圖
補(bǔ)充
角點(diǎn)檢測除了有SIFT算法,還有FAST算法
FAST(Features from Accelerated Segment Test)算法會在像素周圍繪制一個圓,圓內(nèi)包含16個像素,F(xiàn)AST算法是將圓內(nèi)的像素分別與加上一個閾值的圓心像素作比較,若圈內(nèi)出現(xiàn)連續(xù)的幾個像素比加上一個閾值的像素還亮或是暗,則可認(rèn)為圓心是角點(diǎn).FAST是一個很有效率的檢測算法,但是需要確定閾值參數(shù)來檢測角點(diǎn)。
BRIEF(Binary Robust Independent Elementary Features)在OpenCV中主要是通過detectAndCompute()來實(shí)現(xiàn),這個函數(shù)包含兩個部分,檢測和計算,同時也返回兩個結(jié)果.一個是檢測到的關(guān)鍵點(diǎn),一個是描述符.SIFT和SURF也是這樣.關(guān)鍵點(diǎn)的描述符包含了圖像的關(guān)鍵信息,可看作是圖像的另一種表現(xiàn)形式,在比較兩個圖像的時候可以通過比較兩個圖像的特征描述來實(shí)現(xiàn).也可以用來做圖像特征的匹配。
下面將展示通過FAST算法進(jìn)行角點(diǎn)檢測的示例代碼,需要的可以參考一下
package com.xu.opencv; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfKeyPoint; import org.opencv.core.Scalar; import org.opencv.features2d.Features2d; import org.opencv.features2d.ORB; import org.opencv.features2d.SIFT; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; /** * @Title: Image.java * @Description: OpenCV-4.0.0 測試文件 * @Package com.xu.Image * @author: hyacinth * @date: 2022年2月18日12點(diǎn)20分 * @version: V-1.0.0 * @Copyright: 2019 hyacinth */ public class Image { static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { fast(); } public static void fast() { Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg"); Mat gray = new Mat(); Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY); ORB orb = ORB.create(500, 1.2f, 8, 31, 0, 2, ORB.HARRIS_SCORE, 31, 20); MatOfKeyPoint point = new MatOfKeyPoint(); orb.detect(gray, point); Features2d.drawKeypoints(src, point, src, new Scalar(0, 0, 255), Features2d.DrawMatchesFlags_DRAW_RICH_KEYPOINTS); HighGui.imshow("FAST 角點(diǎn)檢測", src); HighGui.waitKey(0); } }
效果圖
到此這篇關(guān)于Java OpenCV圖像處理之SIFT角點(diǎn)檢測詳解的文章就介紹到這了,更多相關(guān)Java OpenCV 角點(diǎn)檢測內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- OpenCV角點(diǎn)檢測的實(shí)現(xiàn)示例
- Python中OpenCV圖像特征和harris角點(diǎn)檢測
- OpenCV半小時掌握基本操作之角點(diǎn)檢測
- OpenCV特征提取與檢測之Shi-Tomasi角點(diǎn)檢測器
- OpenCV特征提取與檢測之Harris角點(diǎn)檢測
- Android基于OpenCV實(shí)現(xiàn)Harris角點(diǎn)檢測
- python opencv角點(diǎn)檢測連線功能的實(shí)現(xiàn)代碼
- OpenCV哈里斯(Harris)角點(diǎn)檢測的實(shí)現(xiàn)
- 基于MFC和OpenCV實(shí)現(xiàn)角點(diǎn)檢測
- OpenCV基于ORB算法實(shí)現(xiàn)角點(diǎn)檢測
相關(guān)文章
詳解Spring與Mybatis的整合方法(基于Eclipse的搭建)
這篇文章主要介紹了Spring與Mybatis的整合方法(基于Eclipse的搭建),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10Java中策略設(shè)計模式的實(shí)現(xiàn)及應(yīng)用場景
策略設(shè)計模式是Java中一種常用的設(shè)計模式,它通過定義一系列算法并將其封裝成獨(dú)立的策略類,從而使得算法可以在不影響客戶端的情況下隨時切換。策略設(shè)計模式主要應(yīng)用于系統(tǒng)中存在多種相似的算法、需要靈活調(diào)整算法邏輯或者需要擴(kuò)展新的算法等場景2023-04-04Spring?Boot中@Autowired注入為空的原因以及解決方法
最近在開發(fā)中遇到了使用@Autowired注解自動裝配時會報空指針,發(fā)現(xiàn)對象并沒有裝配進(jìn)來,下面這篇文章主要給大家介紹了關(guān)于Spring?Boot中@Autowired注入為空的原因以及解決方法,需要的朋友可以參考下2024-01-01使用redisTemplate從redis獲取所有數(shù)據(jù)
這篇文章主要介紹了使用redisTemplate從redis獲取所有數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06