Академический Документы
Профессиональный Документы
Культура Документы
cornerHarris_demo( 0, 0 );
waitKey(0);
return(0);
}
/// Normalizing
normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
convertScaleAbs( dst_norm, dst_norm_scaled );
Shi-Tomasi
Código
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
RNG rng(12345);
char source_window[] = "Image";
/**
* @function main
*/
int main( int argc, char** argv )
{
/// Load source image and convert it to gray
src = imread( "C:\\vision\\imag\\Harris.jpg");
cvtColor( src, src_gray, CV_BGR2GRAY );
goodFeaturesToTrack_Demo( 0, 0 );
waitKey(0);
return(0);
}
/**
* @function goodFeaturesToTrack_Demo.cpp
* @brief Apply Shi-Tomasi corner detector
*/
void goodFeaturesToTrack_Demo( int, void* )
{
if( maxCorners < 1 ) { maxCorners = 1; }
Fast
Código
#include <iostream>
#include <opencv2/opencv.hpp>
#include <math.h>
#include <vector>
#include <fstream>
using namespace std;
using namespace cv;
// Feature
typedef struct feature {
int y;
int x;
unsigned char score;
unsigned char s; // Darker: 1, Similar: 2, Brighter: 3
} FEATURE;
void convertGrayScale()
{
unsigned char r, g, b;
// 3 channel average
int avg = (((r + g + b) / 3) > 0xff) ? 0xff : (r + g + b)
/ 3;
pixel[x][RED] = (unsigned char) avg;
pixel[x][GREEN] = (unsigned char) avg;
pixel[x][BLUE] = (unsigned char) avg;
}
}
}
return true;
}
}
return false;
}
void featureDetection()
{
unsigned char candidate[MAX_CANDIDATE];
unsigned char compare[MAX_CANDIDATE];
void featureScore()
{
unsigned char candidate[MAX_CANDIDATE];
unsigned char compare[MAX_CANDIDATE];
if (findNineConsecutivePixel(compare, feature.y,
feature.x, false))
min = avg;
else
max = avg;
}
void oneFeatureScore()
{
// This function is debug code
// input: y, x
// result: only one feature score, console output
// test coordinate
int y = 20;
int x = 55;
if (findNineConsecutivePixel(compare, y, x, false))
min = avg;
else
max = avg;
}
printf("score: %d\n", max);
// Using formula
int setDark = 0;
int setBright = 0;
comparePixel(compare, candidate, y, x, limit);
findNineConsecutivePixel(compare, y, x, false);
void drawCandidateFeaturePoint()
{
for (int i = 0; i < feature_candidate.size(); i++) {
img.ptr<Vec3b>(feature_candidate[i].y)[feature_candidate[i].x][GREEN]
= 0xff;
img.ptr<Vec3b>(feature_candidate[i].y)[feature_candidate[i].x][RED] =
0;
img.ptr<Vec3b>(feature_candidate[i].y)[feature_candidate[i].x][BLUE] =
0;
img.ptr<Vec3b>(feature_candidate[i].y -
1)[feature_candidate[i].x][GREEN] = 0xff;
img.ptr<Vec3b>(feature_candidate[i].y +
1)[feature_candidate[i].x][GREEN] = 0xff;
img.ptr<Vec3b>(feature_candidate[i].y)[feature_candidate[i].x
- 1][GREEN] = 0xff;
img.ptr<Vec3b>(feature_candidate[i].y)[feature_candidate[i].x
+ 1][GREEN] = 0xff;
}
}
void nonMaximallySuppression()
{
unsigned char corner[MAX_ROWS][MAX_COLS] = {{0}};
unsigned char adjacency[MAX_ADJACENCY];
drawCandidateFeaturePoint();
// Non-maximal suppression
for (int y = 4; y < img.rows - 4; y++) {
for (int x = 4; x < img.cols - 4; x++) {
if (corner[y][x] != 0) {
getAdjacentEightPixels(adjacency, corner, y, x);
if (check)
drawFeature(y, x);
}
}
}
void NMSforSAD()
{
unsigned char corner[MAX_ROWS][MAX_COLS] = {{0}};
unsigned char adjacency[MAX_ADJACENCY];
int number = 1;
ofstream outFile("SAD_Output.txt");
for (int y = 4; y < img.rows - 4; y++) {
for (int x = 4; x < img.cols - 4; x++) {
if (corner[y][x] != 0) {
getAdjacentEightPixels(adjacency, corner, y, x);
if (check) {
int avg =
(img.at<Vec3b>(y - 1, x)[BLUE] +
img.at<Vec3b>(y - 1, x + 1)[BLUE] +
img.at<Vec3b>(y, x + 1)[BLUE] +
img.at<Vec3b>(y + 1, x + 1)[BLUE] +
img.at<Vec3b>(y + 1, x)[BLUE] +
img.at<Vec3b>(y + 1, x - 1)[BLUE] +
img.at<Vec3b>(y, x - 1)[BLUE] +
img.at<Vec3b>(y - 1, x - 1)[BLUE]) / 8;
void fast9()
{
featureDetection(); // stage 1
featureScore(); // stage 2
nonMaximallySuppression(); // stage 3
//NMSforSAD();
}
int main()
{
img = imread("C:\\vision\\imag\\Harris.jpg", CV_LOAD_IMAGE_COLOR);
if (img.empty())
return -1;
imshow("fast9", img);
waitKey(0);
destroyWindow("fast9");
return 0;
}
Resultado