OpenCV是一个开源的计算机视觉库,提供了很多现代计算机视觉所需的各种算法和工具,如图像处理、目标检测、人脸识别、图像分割等等。它的应用广泛,涵盖了安防、自动驾驶、医疗影像处理、机器人、虚拟现实等领域,是计算机视觉领域的重要工具之一。
虽然OpenCV是一个强大的工具,但是学习OpenCV并不是很困难。它是一个面向对象的库,使用C++编写,因此需要具备基本的C++编程知识。它提供了丰富的文档和示例程序,可以帮助初学者更快地掌握OpenCV的应用。
当掌握了OpenCV的基础知识,可以使用OpenCV进行各种计算机视觉任务。例如,可以使用OpenCV进行图像处理,根据图像的特征提取相似性,进行目标检测和识别,进行图像分割以及三维重构等等。因此,掌握OpenCV可以为计算机视觉和图像处理领域的研究和应用提供很大的帮助。
哈哈,我有一个基于opencv实现的sift,我把代码贴出来,你自己看看吧~~~
void sift_detector_and_descriptors(IplImage i_left,IplImage i_right)
{
Mat mat_image_left=Mat(i_left,false);
Mat mat_image_right=Mat(i_right,false);
cv::SiftFeatureDetector pDetector=new cv::SiftFeatureDetector;
pDetector->detect(mat_image_left,left_key_point);
pDetector->detect(mat_image_right,right_key_point);
Mat left_image_descriptors,right_image_descriptors;
cv::SiftDescriptorExtractor descriptor_extractor=new cv::SiftDescriptorExtractor;
descriptor_extractor->compute(mat_image_left,left_key_point,left_image_descriptors);
descriptor_extractor->compute(mat_image_right,right_key_point,right_image_descriptors);
Mat result_l,result_r;
drawKeypoints(mat_image_left,left_key_point,result_l,Scalar::all(-1),0);
drawKeypoints(mat_image_right,right_key_point,result_r,Scalar::all(-1),0);
//imshow("result_of_left_detector_sift",result_l);
//imshow("result_of_right_detector_sift",result_r);
Mat result_of_sift_match;
BruteForceMatcher<L2<float>> matcher;
matchermatch(left_image_descriptors,right_image_descriptors,result_of_point_match);
drawMatches(mat_image_left,left_key_point,mat_image_right,right_key_point,result_of_sift_match,result_of_sift_match);
imshow("matches_of_sift",result_of_sift_match);
imwrite("matches_of_siftjpg",result_of_sift_match);
}
void main()
{
IplImage n_left_image=cvLoadImage("D:\\lenajpg");
IplImage n_right_image=cvLoadImage("D:\\lena_rjpg");
sift_detector_and_descriptors(n_left_image,n_right_image);
cvWaitKey(0);
}
这就是核心代码了。 还有什么不懂,请追问
遇到这种问题一般是opencv 的配置问题,找不到头文件,就说明你的头文件没有被包含,你可以试一下下面的步骤(假如你的opencv安装在D:\Program Files里面)。打开VC9,选择工具-选项-项目各解决方案-VC++目录,将D:\Program Files\opencv\build\include文件夹放到包含文件中,这样应该就可以了,因为opencv2这个文件夹是在include文件夹下,所以包含include这个文件夹的话,程序会在include文件夹下搜寻opencv2\opencvhpp文件。祝你好运!
记得给我分,急需
#include "cvh"
#include <cxcoreh>
#include "highguih"
#include <timeh>
#include <mathh>
#include <ctypeh>
#include <stdioh>
#include <stringh>
// various tracking parameters (in seconds)
const double MHI_DURATION = 05;
const double MAX_TIME_DELTA = 05;
const double MIN_TIME_DELTA = 005;
const int N = 3;
//
const int CONTOUR_MAX_AERA = 16;
// ring image buffer
IplImage buf = 0;
int last = 0;
// temporary images
IplImage mhi = 0;
// MHI: motion history image
int filter = CV_GAUSSIAN_5x5;
CvConnectedComp cur_comp, min_comp;
CvConnectedComp comp;
CvMemStorage storage; CvPoint pt[4];
// 参数:
// img – 输入视频帧
// dst – 检测结果
void update_mhi( IplImage img, IplImage dst, int diff_threshold )
{
double timestamp = clock()/100;
// get current time in seconds
CvSize size = cvSize(img->width,img->height);
// get current frame size
int i, j, idx1, idx2;
IplImage silh;
uchar val;
float temp;
IplImage pyr = cvCreateImage( cvSize((sizewidth & -2)/2, (sizeheight & -2)/2), 8, 1 );
CvMemStorage stor;
CvSeq cont, result, squares;
CvSeqReader reader;
if( !mhi || mhi->width != sizewidth || mhi->height != sizeheight )
{
if( buf == 0 )
{
buf = (IplImage)malloc(Nsizeof(buf[0]));
memset( buf, 0, Nsizeof(buf[0]));
}
for( i = 0; i < N; i++ )
{
cvReleaseImage( &buf[i] );
buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
cvZero( buf[i] );
}
cvReleaseImage( &mhi );
mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
cvZero( mhi );
// clear MHI at the beginning
}
// end of if(mhi)
cvCvtColor( img, buf[last], CV_BGR2GRAY );
// convert frame to grayscale
idx1 = last;
idx2 = (last + 1) % N;
// index of (last - (N-1))th frame
last = idx2;
// 做帧差
silh = buf[idx2];
cvAbsDiff( buf[idx1], buf[idx2], silh );
// get difference between frames
// 对差图像做二值化
cvThreshold( silh, silh, 30, 255, CV_THRESH_BINARY );
// and threshold it
cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION );
// update MHI
cvCvtScale( mhi, dst, 255/MHI_DURATION,
(MHI_DURATION - timestamp)255/MHI_DURATION );
cvCvtScale( mhi, dst, 255/MHI_DURATION, 0 );
// 中值滤波,消除小的噪声
cvSmooth( dst, dst, CV_MEDIAN, 3, 0, 0, 0 );
// 向下采样,去掉噪声
cvPyrDown( dst, pyr, 7 );
cvDilate( pyr, pyr, 0, 1 );
// 做膨胀 *** 作,消除目标的不连续空洞
cvPyrUp( pyr, dst, 7 );
//
// 下面的程序段用来找到轮廓
//
// Create dynamic structure and sequence
stor = cvCreateMemStorage(0);
cont = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , stor);
// 找到所有轮廓
cvFindContours( dst, stor, &cont, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
// 直接使用CONTOUR中的矩形来画轮廓
for(;cont;cont = cont->h_next)
{
CvRect r = ((CvContour)cont)->rect;
if(rheight rwidth > CONTOUR_MAX_AERA) // 面积小的方形抛弃掉
{
cvRectangle( img, cvPoint(rx,ry),
cvPoint(rx + rwidth, ry + rheight),
CV_RGB(255,0,0), 1, CV_AA,0);
}
} // free memory
cvReleaseMemStorage(&stor);
cvReleaseImage( &pyr );
}
int main(int argc, char argv)
{
IplImage motion = 0;
CvCapture capture = 0; //视频获取结构
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
//原型:extern int isdigit(char c); //用法:#include <ctypeh> 功能:判断字符c是否为数字 说明:当c为数字0-9时,返回非零值,否则返回零。
capture = cvCaptureFromCAM( argc == 2 argv[1][0] - '0' : 1 );
else if( argc == 2 )
capture = cvCaptureFromAVI( argv[1] );
if( capture )
{
cvNamedWindow( "Motion", 1 );
for(;;)
{
IplImage image;
if( !cvGrabFrame( capture )) //从摄像头或者视频文件中抓取帧
break;
image = cvRetrieveFrame( capture );
//取回由函数cvGrabFrame抓取的图像,返回由函数cvGrabFrame 抓取的图像的指针
if( image )
{
if( !motion )
{
motion = cvCreateImage( cvSize(image->width,image->height), 8, 1 );
cvZero( motion );
motion->origin = image->origin;
/// 0 - 顶—左结构, 1 - 底—左结构 (Windows bitmaps 风格) /
}
}
update_mhi( image, motion, 60 );
cvShowImage( "Motion", image );
if( cvWaitKey(10) >= 0 )
break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Motion" );
}
return 0;
}
以上就是关于opencv难学吗能干什么全部的内容,包括:opencv难学吗能干什么、求opencv实现sift算法的程序、vs2008 的stdafx问题(代码在下面的问题补充里面),图像处理,OpenCV 2.3.1实例程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)