OpenCV基础

来源:互联网 发布:广州java培训价格 编辑:程序博客网 时间:2024/05/22 02:53

OpenCV中最常包含的静态库为opencv.hppcxcore.hhighgui.h

OpenCVIplImage结构体最重要的参数为widthheightimagedatanchannels

 

1、读取图像函数cvLoadImage””

2、新建图像函数cvCreateImage (size,depth,channels)

3、创建窗口函数cvNamedWindow

4在指定窗口中显示图像 cvShowImage

5、将彩色图像转化为黑白图像cvCvtColor

5等待按键事件 cvWaitKey

这几个函数的应用:

#include"stdafx.h"

#include<opencv.hpp>

#include<cxcore.h>

#include<highgui.h>

#include<stdio.h>

 

 

int main() 

#if 0

    cv::Mat image=cv::imread("lena.jpg");//读入一张图片  

    cv::imshow("Test for Opencv2.4.9",image);//显示一张图片  

    cv::waitKey(); 

#else

    IplImage *ImageInfo = cvLoadImage("1.jpg");

    unsignedshort mWide = ImageInfo->width;

    unsignedshort mHeight = ImageInfo->height;

    unsignedchar *ImageData = (unsignedchar*)ImageInfo->imageData;

    unsignedchar nChannel = ImageInfo->nChannels;

 

    IplImage *GrayImage = cvCreateImage(cvSize(mWide,mHeight),8,1);

    cvCvtColor(ImageInfo,GrayImage,CV_RGB2GRAY);

 

    printf("mWide = %d\r\n mHeight = %d\r\n nChannel = %d\r\n",mWide,mHeight,nChannel);

 

 

    cvNamedWindow("the Image of show:");

    cvShowImage("the Image of show:",ImageInfo);

 

    cvNamedWindow("the GrayImage of show:");

    cvShowImage("the GrayImage of show:",GrayImage);

 

    cvWaitKey(-2);

#endif

   return 0; 

0 0