#include #include #include #include #include "cvcam.h" #include "cv.h" #include "highgui.h" /************************************************************************ * ************************************************************************/ int main( int argc, char** argv ) { IplImage* frame, *frame_copy = 0; IplImage *imgB,*imgG,*imgR,*imgA; uchar *data; CvScalar mBGR, dBGR; double mR,mG,mB; double dR,dG,dB; int height,width,step,channels; int i,j,k; frame=cvLoadImage("out.png", 1); if( !frame ) exit(0); cvNamedWindow( "result", 1 ); // Exibe região com a cor segmentada cvShowImage("result", frame ); mBGR = cvAvg(frame,0); mB=mBGR.val[0]; mG=mBGR.val[1]; mR=mBGR.val[2]; cvAvgSdv(frame, &mBGR, &dBGR, 0); dB=dBGR.val[0]; dG=dBGR.val[1]; dR=dBGR.val[2]; printf ("Mean R,G,B: %.2lf - %.2lf - %.2lf\n",mR,mG,mB); printf ("StdDev R,G,B: %.2lf - %.2lf - %.2lf\n",dR,dG,dB); cvWaitKey(0); // Parte II frame=cvLoadImage("imagem.jpg", 1); if( !frame ) exit(0); if( !frame_copy ) frame_copy = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); if( frame->origin == IPL_ORIGIN_TL ) cvCopy( frame, frame_copy, 0 ); else cvFlip( frame, frame_copy, 0 ); // get the image data height = frame->height; width = frame->width; step = frame->widthStep; channels = frame->nChannels; data = (uchar *)frame->imageData; printf("Processing a %dx%d image with %d channels\n",height,width,channels); for(i=0;i= (mB-dB) && data[i*step+j*channels+0] <= (mB+dB)) && (data[i*step+j*channels+1] >= (mG-dG) && data[i*step+j*channels+1] <= (mG+dG)) && (data[i*step+j*channels+2] >= (mR-dR) && data[i*step+j*channels+2] <= (mR+dR)) ) { data[i*step+j*channels+0]=255; data[i*step+j*channels+1]=255; data[i*step+j*channels+2]=255; } else { data[i*step+j*channels+0]=0; data[i*step+j*channels+1]=0; data[i*step+j*channels+2]=0; } } /* detect_and_draw( frame_copy ); */ cvShowImage("result", frame ); cvWaitKey(0); cvReleaseImage( &frame_copy ); cvDestroyWindow("result"); return 0; }