zoukankan      html  css  js  c++  java
  • 【OpenCV学习】Laplace变换(视频边界检测)

    作者:gnuhpc
    出处:http://www.cnblogs.com/gnuhpc/

    #include "cv.h"
    #include "highgui.h"
    #include <ctype.h>
    #include <stdio.h>
    int main(int argc , char **argv)
    {
        IplImage *laplace = 0;
        IplImage *coloelaplace = 0;
        IplImage *planes[3]={0,0,0};//多个图像面
        CvCapture *capture = 0;
        if (argc==1|| (argc==2 && strlen(argv[1])==1 && isdigit(argv[1][0])))
        {
            capture = cvCaptureFromCAM(-1);
        }
        else if(argc==2)
        {
            capture = cvCaptureFromAVI(argv[1]);
        }
        if (!capture)
        {
            fprintf(stderr,"Could not initialize capturing.../n");
            return -1;
        }
        cvNamedWindow("main",0);
        for (;;)
        {
            IplImage *frame=0;
            int i;
            frame = cvQueryFrame(capture);//从摄像头或者文件中抓取并返回一帧
            if (!frame)
            {
                break;
            }
            if (!laplace)
            {
                for (i=0;i<3;i++)
                {
                    planes[i]=cvCreateImage(cvSize(frame->width,frame->height),8,1);
                }
                laplace=cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_16S,1);
                coloelaplace=cvCreateImage(cvSize(frame->width,frame->height),8,3);
            }
            cvCvtPixToPlane(frame,planes[0],planes[1],planes[2],0);
            //#define cvCvtPixToPlane cvSplit
            for (i=0;i<3;i++)
            {
                cvLaplace(planes[i],laplace,3);//计算图像planes[i]的 Laplacian 变换
                cvConvertScaleAbs(laplace,planes[i],1,0);//planes[]=ABS(laplace)
            }
            cvCvtPlaneToPix(planes[0],planes[1],planes[2],0,coloelaplace);
            //#define cvCvtPlaneToPix cvMerge
           
            coloelaplace->origin=frame->origin;
           
            cvShowImage("main",coloelaplace);
            if (cvWaitKey(10)>=0)
            {
                break;
            }
        }
       
        cvReleaseCapture(&capture);
        cvDestroyWindow("main");
        return 0;
    }

    作者:gnuhpc
    出处:http://www.cnblogs.com/gnuhpc/


                   作者:gnuhpc
                   出处:http://www.cnblogs.com/gnuhpc/
                   除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。


    分享到:

  • 相关阅读:
    SpringMVC扩展
    反射机制
    python day9
    python day8
    python day7
    python day6
    python day4
    python day3
    python day2
    python day1
  • 原文地址:https://www.cnblogs.com/gnuhpc/p/2715884.html
Copyright © 2011-2022 走看看