資源簡介
用c++配置opencv庫實(shí)現(xiàn)的提取點(diǎn)特征的moravec算子,自己編寫,完全可用
代碼片段和文件信息
//?M算子.cpp:?定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#include?“stdafx.h“
#include??
#include“opencv2/highgui/highgui.hpp“????
#include??
#include??
#include??
using?namespace?std;
using?namespace?cv;
uchar?getpix(Mat&?src?int?x?int?y)
{
uchar*?pt?=?src.ptr(y);
return?pt[x];
}
void?setMatpix(Mat&?dst?int?x?int?y?float?value)
{
uchar*?pt?=?dst.ptr(y);
pt[x]?=?value;
}
/*
src:輸入圖像
kernel:移動的窗口的大小
threshold:設(shè)置的閥值大小
*/
void?Moravec(Mat&?src?int?kernal?float?threshold?vector*?corPoint)
{
int?halfKernal?=?kernal?/?2;
//float?moveValue[4]?=?{?0?};??
float?minValue;
Mat?dst(src.size()?CV_8UC1?Scalar(0));
//遍歷圖像時候,沒有對圖像的邊緣進(jìn)行處理(邊緣是窗口大小一半)??
for?(int?y?=?halfKernal;?y? {
for?(int?x?=?halfKernal;?x? {
float?moveValue[4]?=?{?0?};
//對圖像的每一個點(diǎn)在?0°、45°、90°135°的變化量??
for?(int?win?=?-halfKernal;?win? {
moveValue[0]?+=?pow(getpix(src?x?+?win?y)?-?getpix(src?x?+?win?+?1?y)?2);//0°方向變化量??
moveValue[1]?+=?pow(getpix(src?x?+?win?y?+?win)?-?getpix(src?x?+?win?+?1?y?+?win?+?1)?2);//45°方向變化量??
moveValue[2]?+=?pow(getpix(src?x?y?+?win)?-?getpix(src?x?y?+?win?+?1)?2);//90°方向變化量??
moveValue[3]?+=?pow(getpix(src?x?-?win?y?+?win)?-?getpix(src?x?-?win?-?1?y?+?win?+?1)?2);//135°方向變化量??
}
//計算四個方向移動的最小值??
minValue?=?moveValue[0];
minValue?=?minValue?>?moveValue[1]???moveValue[1]?:?minValue;
minValue?=?minV
評論
共有 條評論