차근차근/OpenCV
매칭률 구하기
매칭률 구하기를 하기 위한 무작정 자료수집
이게 관련 함수인가 봄
CV_TM_SQDIFF
CV_TM_SQDIFF_NORMED
CV_TM_CCOEFF
CV_TM_CCOEFF_NORMED
CV_TM_CCORR
CV_TM_CCORR_NORMED
opencv제대로 배우기 p.298 - p.303 템플릿 매칭
템플릿 매칭(Template Matching)
= 큰 이미지에서 특정 작은 이미지를 찾는 알고리즘
(http://www.obg.co.kr/?mid=programming&document_srl=8840&listStyle=viewer&page=8)
cvMatchTemplate()
입력 영상을 주어진 영상 패치로 스캔하면서 매칭을 수행
void cvMatchTemplate(
const CvArr* image,
const CvArr* templ,
CvArr* result,
int method
);
하나의 8비트 또는 실수형 영상, 또는 트루컬러 영상을 입력으로 사용.
제곱차 매칭 방법(method = CV_TM_SQDIFF)
픽셀값을 제곱차를 이용.
완벽하게 일치하면 0을 반환, 일치하지 않으면 값이 커진다.
상관관계 매칭 방법(method = CV_TM_CCORR)
템플릿과 입력 영상의 곱을 제곱하여 모두 더한다.
완벽하게 일치하면 값이 크게 나오고, 일치하지 않으면 작은 값이 나오거나 0이 나온다.
상관관계 매칭 방법(method = CV_TM_CCOEFF)
템플렛과 입력 영상 각각의 평균을 고려한 매칭을 수행
완벽하게 일치하면 1을 반환하고, 완전히 불일치하면 -1을 반환
이 값이 0을 반환하는 경우는 두 영상 사이에 전혀 연관성이 없음을 의미
http://www.larmor.com/projects/JavaOpenCVMatchTemplate/doc/com/larmor/opencv/MatchTemplate.html
(CV_TM_SQDIFF) : 제곱의 차이
(CV_TM_SQDIFF_NORMED) : 정규화 제곱 차이
(CV_TM_CCORR) : 교차 상관
(CV_TM_CCORR_NORMED) : 정규화 된 상호 상관 관계
(CV_TM_CCOEFF) : 상관 계수
(CV_TM_CCOEFF_NORMED) : 정규화 상관 계수 (NCC - 빠른 정상화 간 상관 관계)
com.larmor.opencv
Class MatchTemplate
java.lang.Object com.larmor.opencv.MatchTemplate
public class MatchTemplate
- extends Object
This Class wraps OpenCV (the Open Source Computer Vision Library http://www.intel.com/technology/computing/opencv/index.htm)
function cvMatchTemplate and implements other methods for utilities result
visualization.
The class uses JAI (Java Advanced Imaging) API and JAI-Java Image I/O Technology (for dowload: https://jai.dev.java.net/ and
https://jai-imageio.dev.java.net/).
The OpenCV function
cvMatchTemplate compares overlapped image of size w�h with a template using the
specified method and stores the comparison results to result image. The possible
methods for matching are:
- (CV_TM_SQDIFF): squared difference
- (CV_TM_SQDIFF_NORMED): normalized squared difference
- (CV_TM_CCORR): cross correlation
- (CV_TM_CCORR_NORMED): normalized cross correlation
- (CV_TM_CCOEFF): correlation coefficient
- (CV_TM_CCOEFF_NORMED): normalized correlation coefficient (NCC - Fast
Normalized Cross-Correlation)
see http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html
and http://www.cs.ubc.ca/~deaton/remarks_ncc.html
I
denotes image, T
- template, R
-
result. The summation is done over template and/or the image patch:
x'=0..w-1, y'=0..h-1
):
method=CV_TM_SQDIFF: R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]2 method=CV_TM_SQDIFF_NORMED: R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]2/sqrt[sumx',y'T(x',y')2븉umx',y'I(x+x',y+y')2] method=CV_TM_CCORR: R(x,y)=sumx',y'[T(x',y')뷞(x+x',y+y')] method=CV_TM_CCORR_NORMED: R(x,y)=sumx',y'[T(x',y')뷞(x+x',y+y')]/sqrt[sumx',y'T(x',y')2븉umx',y'I(x+x',y+y')2] method=CV_TM_CCOEFF: R(x,y)=sumx',y'[T'(x',y')뷞'(x+x',y+y')], where T'(x',y')=T(x',y') - 1/(w뷻)븉umx",y"T(x",y") I'(x+x',y+y')=I(x+x',y+y') - 1/(w뷻)븉umx",y"I(x+x",y+y") method=CV_TM_CCOEFF_NORMED: R(x,y)=sumx',y'[T'(x',y')뷞'(x+x',y+y')]/sqrt[sumx',y'T'(x',y')2븉umx',y'I'(x+x',y+y')2]
- Version:
- Vers. 0.5 beta (March.2008)
- Author:
- Pier Paolo Ciarravano Larmor License: GNU General Public License
Field Summary | |
---|---|
static int |
CV_TM_CCOEFF
CV_TM_CCOEFF: correlation coefficient |
static int |
CV_TM_CCOEFF_NORMED
CV_TM_CCOEFF_NORMED: normalized correlation coefficient (NCC - Fast Normalized Cross-Correlation) see http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html and http://www.cs.ubc.ca/~deaton/remarks_ncc.html |
static int |
CV_TM_CCORR
CV_TM_CCORR: cross correlation |
static int |
CV_TM_CCORR_NORMED
CV_TM_CCORR_NORMED: normalized cross correlation |
static int |
CV_TM_SQDIFF
CV_TM_SQDIFF: squared difference |
static int |
CV_TM_SQDIFF_NORMED
CV_TM_SQDIFF_NORMED: normalized squared difference |
Constructor Summary | |
---|---|
MatchTemplate(BufferedImage source,
BufferedImage template)
Init source and template image for matchTemplate... methods, these images using java.awt.color.ColorSpace.CS_GRAY. |
Method Summary | |
---|---|
static void |
displayBufferedImage(BufferedImage image,
String title)
Utility method for display a BufferedImage. |
static void |
displayBufferedImageCrossPoint(BufferedImage image,
String title,
Point center,
int x, int y) Utility method for display a BufferedImage and draw cross point on it. |
float[] |
getCvMatchTemplateFloat()
You can call this method only after matchTemplate(...) methods |
static BufferedImage |
getGrayBufferedImage(RenderedImage image)
Use this method to costruct image and template source images for costructor with java.awt.color.ColorSpace.CS_GRAY. |
static BufferedImage |
getImageGrayFromImage(BufferedImage image,
int x, int y, int w, int h) Use this method to costruct TYPE_BYTE_GRAY image rectangle of w x h pixels (starting from x and y of original image) from input image. |
BufferedImage |
getMatchImage()
You can call this method only after matchTemplate(...) methods |
int |
getResultHeight()
You can call this method only after matchTemplate(...) methods |
int |
getResultWidth()
You can call this method only after matchTemplate(...) methods |
Point |
matchTemplate(int method)
This method match entire image with template using the specified method and return point of best matches. |
Point |
matchTemplate(int x,
int y, int w, int h, int method) This method match rectangle image of w x h pixels (starting from x and y of original image) with template using the specified method and return point of best matches. |
Point |
matchTemplateBestPoint(int method)
This method matchs entire image with template using the specified method and return point of best matches. |
Point |
matchTemplateBestPoint(int x,
int y, int w, int h, int method) This method match rectangle image of w x h pixels (starting from x and y of original image) with template using the specified method and return point of best matches. |
Methods inherited from class java.lang.Object |
---|
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
---|
CV_TM_CCOEFF
public static final int CV_TM_CCOEFF
- CV_TM_CCOEFF: correlation coefficient
- See Also:
- Constant Field Values
CV_TM_CCOEFF_NORMED
public static final int CV_TM_CCOEFF_NORMED
- CV_TM_CCOEFF_NORMED: normalized correlation coefficient (NCC - Fast
Normalized Cross-Correlation)
see http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html
and http://www.cs.ubc.ca/~deaton/remarks_ncc.html- See Also:
- Constant Field Values
CV_TM_CCORR
public static final int CV_TM_CCORR
- CV_TM_CCORR: cross correlation
- See Also:
- Constant Field Values
CV_TM_CCORR_NORMED
public static final int CV_TM_CCORR_NORMED
- CV_TM_CCORR_NORMED: normalized cross correlation
- See Also:
- Constant Field Values
CV_TM_SQDIFF
public static final int CV_TM_SQDIFF
- CV_TM_SQDIFF: squared difference
- See Also:
- Constant Field Values
CV_TM_SQDIFF_NORMED
public static final int CV_TM_SQDIFF_NORMED
- CV_TM_SQDIFF_NORMED: normalized squared difference
- See Also:
- Constant Field Values
Constructor Detail |
---|
MatchTemplate
public MatchTemplate(BufferedImage source, BufferedImage template)
- Init source and template image for matchTemplate... methods, these images
using java.awt.color.ColorSpace.CS_GRAY.
For costruct these images use:java.awt.image.RenderedImage image = javax.imageio.ImageIO.read(new File(source)); java.awt.image.BufferedImage imageBI = MatchTemplate.getGrayBufferedImage(sourceImg);
- Parameters:
source
- source BufferedImage using java.awt.color.ColorSpace.CS_GRAYtemplate
- template BufferedImage using java.awt.color.ColorSpace.CS_GRAY
Method Detail |
---|
displayBufferedImage
public static void displayBufferedImage(BufferedImage image, String title)
- Utility method for display a BufferedImage.
-
- Parameters:
image
- input imagetitle
- window title string
displayBufferedImageCrossPoint
public static void displayBufferedImageCrossPoint(BufferedImage image, String title, Point center, int x, int y)
- Utility method for display a BufferedImage and draw cross point on it.
-
- Parameters:
image
- input imagetitle
- window title stringcenter
- relative center point returned from matchTemplate... methodsx
- the x coordinates of the pixel used in matchTemplate... methodsy
- the y coordinates of the pixel used in matchTemplate... methods
getCvMatchTemplateFloat
public float[] getCvMatchTemplateFloat()
- You can call this method only after matchTemplate(...) methods
-
- Returns:
- result pixels matrix image
getGrayBufferedImage
public static BufferedImage getGrayBufferedImage(RenderedImage image)
- Use this method to costruct image and template source images for costructor
with java.awt.color.ColorSpace.CS_GRAY.
Use:java.awt.image.RenderedImage image = javax.imageio.ImageIO.read(new File(source)); java.awt.image.BufferedImage imageBI = MatchTemplate.getGrayBufferedImage(sourceImg);
-
- Parameters:
image
- input java.awt.image.RenderedImage- Returns:
- java.awt.color.ColorSpace.CS_GRAY image
getImageGrayFromImage
public static BufferedImage getImageGrayFromImage(BufferedImage image, int x, int y, int w, int h)
- Use this method to costruct TYPE_BYTE_GRAY image rectangle of w x h pixels
(starting from x and y of original image) from input image.
-
- Parameters:
image
- BufferedImagex
- the x coordinates of the pixel locationy
- the y coordinates of the pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectangle- Returns:
- BufferedImage image
getMatchImage
public BufferedImage getMatchImage()
- You can call this method only after matchTemplate(...) methods
-
- Returns:
- TYPE_BYTE_GRAY BufferedImage of result pixels matrix image
getResultHeight
public int getResultHeight()
- You can call this method only after matchTemplate(...) methods
-
- Returns:
- result image Height
getResultWidth
public int getResultWidth()
- You can call this method only after matchTemplate(...) methods
-
- Returns:
- result image Width
matchTemplate
public Point matchTemplate(int method)
- This method match entire image with template using the specified method and
return point of best matches. It Uses java implementation to find minimum and
maximum element for best matches.
Using this method, you can call getCvMatchTemplateFloat(),getResultWidth() and getResultHeight() methods for return result float[] matrix and image dimension. -
- Parameters:
method
- the comparison methods- Returns:
- java.awt.Point of best matches
matchTemplate
public Point matchTemplate(int x, int y, int w, int h, int method)
- This method match rectangle image of w x h pixels (starting from x and y of
original image) with template using the specified method and return point of
best matches. It Uses java implementation to find minimum and maximum element
for best matches.
Using this method, you can call getCvMatchTemplateFloat(),getResultWidth() and getResultHeight() methods for return result float[] matrix and image dimension. -
- Parameters:
x
- the x coordinates of the pixel locationy
- the y coordinates of the pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectanglemethod
- the comparison methods- Returns:
- java.awt.Point of best matches
matchTemplateBestPoint
public Point matchTemplateBestPoint(int method)
- This method matchs entire image with template using the specified method and return point of best matches. It Uses OpenCV internal function cvMinMaxLoc for find minimum and maximum element for best matches.
-
- Parameters:
method
- the comparison methods- Returns:
- java.awt.Point of best matches
matchTemplateBestPoint
public Point matchTemplateBestPoint(int x, int y, int w, int h, int method)
- This method match rectangle image of w x h pixels (starting from x and y of original image) with template using the specified method and return point of best matches. It Uses OpenCV internal function cvMinMaxLoc for find minimum and maximum element for best matches.
-
- Parameters:
x
- the x coordinates of the pixel locationy
- the y coordinates of the pixel locationw
- Width of the pixel rectangleh
- Height of the pixel rectanglemethod
- the comparison methods- Returns:
- java.awt.Point of best matches
매칭률에 대한 질문과 답변 url
cvMatchTemplate
http://aidenjlee.tistory.com/116
cvMatchTemplate :)
OpenCV 학습,
void CFollowDlg : : MatchTemplate (CString Path) {
/ / = 0 더블.;
IplImage * imgSrc = cvLoadImage (Path);
IplImage * imgTemp = cvLoadImage ( "C : \ \ t.bmp");
CvSize sizeSrc = cvGetSize (imgSrc);
CvSize의 sizeTemp = cvGetSize (imgTemp);
CvSize의 sizeResult = cvSize (sizeSrc.width - sizeTemp.width 1, sizeSrc.height - sizeTemp.height 1);
IplImage * imgResult = cvCreateImage (sizeResult, IPL_DEPTH_32F, 1);
(imgSrc, imgTemp, imgResult, CV_TM_CCORR_NORMED) cvMatchTemplate;
/ / = cvMatchShapes (imgSrc, imgTemp, CV_CONTOURS_MATCH_I3);
dMax = 0 .;
CvPoint Point = cvPoint (0,0);
/ /if(!a) MessageBox ( "성공하지 못함!", MB_OK) ;
for (int cx=0 ; cx
{
for (int cy=0 ; cy
{
float fTemp = CV_IMAGE_ELEM(imgResult,float,cy,cx);
if (dMax < fTemp)
{
dMax = fTemp;
point = cvPoint(cx,cy);
}
}
}
CvPoint point2 = cvPoint(point.x+sizeTemp.width,point.y+sizeTemp.height);
cvRectangle(imgSrc,point,point2,cvScalar(255));
cvNamedWindow( "Test", CV_WINDOW_AUTOSIZE );
cvShowImage("Test",imgSrc);
/* for(;;)
{
int k = cvWaitKey(5);
if( k == 27 ) break;
}
*/
}
void CFollowDlg::OnButton4()
{
// TODO: Add your control notification handler code here
CString path;
CFileDialog dlg(TRUE);
if(dlg.DoModal()==IDOK)
path=dlg.GetPathName();
MatchTemplate(path);
}
소개 cvMatchTemplate () 설명서 :
프로토 타입 :
void cvMatchTemplate( const CvArr* image, const CvArr* templ,
CvArr* result, int method );
이미지
이미지를 검색할 수 있습니다. 비트 이미지를 포인트 또는 32 - 비트 부동 단일 그것은이어야 채널, 8 -
templ
검색 서식 파일, 이미지가 없습니다 입력보다 큰 이미지 및 입력 유형을 가지고있는 동일한 데이터
결과
이미지 비교 매핑 결과를 중. 단일 채널, 32 - 이미지는 승 비트 H는 부동 소수점 ×. 않으면과 templ 반장님입니다 w × 후, 결과) 1 +1) ×을 (H 조 - H를해야합니다 (- 승 w
방법
를 지정 검색 방법 : 기능 cvMatchTemplate과 함수 cvCalcBackProjectPatch 비슷한. 예금에 비해 그 결과 것입니다 결과가 슬라이드를 통해 전체 이미지 이미지와, 비교 메서드는 지정된와 templ과 영역을 오버랩의 × H 조 w 이미지 크기.
함수 또는 *) CV_TM_SQDIFF cvMinMaxLoc의 이용을 통하여 최소 글로벌 찾아 마무리 비교를 위해) 최대 (CV_TM_CCORR * 및 CV_TM_CCOEFF의 *.
'차근차근 > OpenCV' 카테고리의 다른 글
몰라요..매칭률검색하다가 나옴 (0) | 2014.08.06 |
---|---|
OpenCV를 이용한 Template Matching (0) | 2014.08.06 |
SURF에 의한 특징점 검출 (0) | 2014.08.06 |
외부에서 이미지 입력받기 (0) | 2014.08.06 |
std::vector<cv::String,std::allocator<cv::String>>ldata> (0) | 2014.08.06 |
'차근차근/OpenCV'의 다른글
- 현재글매칭률 구하기