#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <math.h>
using namespace cv;
int g_slider_position=0,high=0,low=0;
CvCapture* capture = NULL;
void onTrackbarSlide(int pos) {}
//------------------------------------------
int main( int argc, char* argv[] ) {
capture = cvCreateFileCapture( "C:\\Users\\abc\\Desktop\\MVI_0035.avi" );
if(!capture){
return -1;
}
CvSize size = cvSize(
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
);
IplImage* frame = cvCreateImage(size,IPL_DEPTH_8U,3);
IplImage* grey = cvCreateImage(size,IPL_DEPTH_8U,1);
IplImage* edge = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* dirsx = cvCreateImage(size, IPL_DEPTH_16S, 1);
IplImage* dirsy = cvCreateImage(size, IPL_DEPTH_16S, 1);
IplImage* dirsxy = cvCreateImage(size, IPL_DEPTH_16S, 1);
IplImage* dirx = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* diry = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* dirxy = cvCreateImage(size, IPL_DEPTH_8U, 1);
while( (frame=cvQueryFrame(capture)) != NULL ) {
cvCvtColor(frame,grey,CV_RGB2GRAY);
cvNamedWindow( "gray", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "canny", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "sobel", CV_WINDOW_AUTOSIZE );
cvCreateTrackbar("T","gray",&g_slider_position,1000,onTrackbarSlide);
cvCreateTrackbar("high","canny",&high,1000,onTrackbarSlide);
cvCreateTrackbar("low","canny",&low,1000,onTrackbarSlide);
cvSmooth(grey,grey,CV_GAUSSIAN,13);
cvCanny(grey, edge, low, high);
//-----------------------
cvSobel(grey,dirsx,1,0, 3);
cvConvertScaleAbs(dirsx,dirx,1,0);
cvSobel(grey,dirsy,0,1, 3);
cvConvertScaleAbs(dirsy,diry,1,0);
cvAddWeighted(dirsx,0.707,dirsy,0.707,0,dirsxy);
cvConvertScaleAbs(dirsxy,dirxy,1,0);
//-------------------
cvShowImage( "gray", grey );
cvShowImage( "canny", edge );
cvShowImage("sobel", dirxy);
cvWaitKey(1001-g_slider_position);
}
cvReleaseImage( &frame );
cvReleaseImage( &grey );
cvReleaseCapture( &capture );
cvDestroyWindow( "gray" );
cvDestroyWindow( "canny" );
cvDestroyWindow( "sobel" );
return(0);
}
No comments:
Post a Comment