|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: |
#include "stdafx.h"
#include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include <ctype.h>
#include <stdio.h>
IplImage *frame1 = NULL, *frame2 = NULL, *frame3 = NULL;
IplImage *diff1 = NULL, *diff2 = NULL, *result = NULL;
IplImage* cannyImg;
IplImage *grayImg = 0; // gray image
int main(int argc, char** argv)
{
int height,width,step,channels;
uchar *data1, *data2, *data3, *diffData1, *diffData2, *resultData;
int i, j;
int threshold = 30;
int diff;
/* Start capturing */
CvCapture* capture = 0;
/*capturing from cam
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 &&
isdigit(argv[1][0])))
capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
else if( argc == 2 )
capture = cvCaptureFromAVI( argv[1] );
*/
capture = cvCaptureFromAVI( "car.avi" );
int mode = CV_RETR_EXTERNAL;
mode = CV_RETR_CCOMP; //detect both outside and inside contour
if( !capture )
{
fprintf(stderr,"Could not initialize...\n");
return -1;
}
/* Capture 1 video frame for initialization */
frame2 = cvQueryFrame(capture); // retrive from the video
frame3 = cvQueryFrame(capture);
/* Create windows */
cvNamedWindow("Actual Video", 1); // creating window
cvNamedWindow("With Differencing", 1);
cvMoveWindow("With Differencing", 500,0);
cvNamedWindow("BackGround", 1);
cvMoveWindow("BackGround", 0,350);
cvNamedWindow("canny Edge",1);
cvMoveWindow("canny Edge", 750, 350);
CvBGStatModel* bg_model;
bg_model =cvCreateGaussianBGModel( frame2 );
/* Get properties of frame */
width = frame2->width;
height = frame2->height;
step = frame2->widthStep;
channels = frame2->nChannels;
int key=-1;
while(key != 'q')
{
/* Get consecutive frames */
frame1 = cvCloneImage(frame2);
// cvReleaseData(frame2);
// cvReleaseImage(&frame2);
frame2 = cvCloneImage(frame3);
// cvReleaseData(frame3);
// cvReleaseImage(&frame);
frame3 = cvQueryFrame(capture);
/* Initialize difference and result frames */
diff1 = cvCloneImage(frame3);
diff2 = cvCloneImage(frame3);
result = cvCloneImage(frame3);
/* Image is treated as as unsigned char data hence we use an
unsigned char pointer to point to the same to access pixels */
data1 = (uchar *)frame1->imageData;
data2 = (uchar *)frame2->imageData;
data3 = (uchar *)frame2->imageData;
diffData1 = (uchar *)diff1->imageData;
diffData2 = (uchar *)diff2->imageData;
resultData = (uchar *)result->imageData;
/* Get difference of frames */
cvAbsDiff(frame2,frame1,diff1);
cvAbsDiff(frame3,frame2,diff2);
cvUpdateBGStatModel( frame2, bg_model );
// canny edge detection
// Check for threshold
for(i=0;i<=height-1;i++)
{
for(j=0;j<=width-1;j++)
{
//Difference depends on sum of pixels on each channel
if(((diffData1[i*step+j*channels+0] +
diffData1[i*step+j*channels+1] + diffData1[i*step+j*channels+2]) >
threshold) && ((diffData2[i*step+j*channels+0] +
diffData2[i*step+j*channels+1] + diffData2[i*step+j*channels+2]) >
threshold))
{
resultData[i*step+j*channels+0] = 255;
resultData[i*step+j*channels+1] = 255;
resultData[i*step+j*channels+2] = 255;
}
else
{
resultData[i*step+j*channels+0] = 0;
resultData[i*step+j*channels+1] = 0;
resultData[i*step+j*channels+2] = 0;
}
}
}
//end of frame differencing with binarization
grayImg = cvCreateImage( cvSize(result->width, result->height),
IPL_DEPTH_8U, 1 );
//convert original color image (3 channel rgb color image) to gray-level image
cvCvtColor( result, grayImg, CV_BGR2GRAY );
cannyImg = cvCreateImage(cvGetSize(result), IPL_DEPTH_8U, 1);
cvCanny(grayImg, cannyImg, 50, 150, 3);
cvShowImage("Actual Video",frame2);
cvShowImage("With Differencing",result);
cvShowImage("BackGround", bg_model->background);
cvShowImage("canny Edge", cannyImg);
// cvReleaseData(frame1);
cvReleaseImage(&frame1);
// cvReleaseData(diff1);
cvReleaseImage(&diff1);
// cvReleaseData(diff2);
cvReleaseImage(&diff2);
// cvReleaseData(result);
cvReleaseImage(&result);
key = cvWaitKey(10);
}//end of while
cvDestroyWindow("Actual Video");
cvDestroyWindow("With Differencing");
cvDestroyWindow("BackGround");
cvDestroyWindow("canny");
cvReleaseCapture(&capture);
return 0;
}
|
Advertisement
| Hall of Fame |