本文整理汇总了C++中cvErode函数的典型用法代码示例。如果您正苦于以下问题:C++ cvErode函数的具体用法?C++ cvErode怎么用?C++ cvErode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cvErode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cvCvtColor
void Hand_recognition::Detect_Skin(IplImage *src, IplImage *dst){
cvCvtColor(src, img_YCrCb, CV_BGR2YCrCb);
cvCvtColor(src, img_HSV, CV_BGR2HSV);
cvZero(dst);
for(int i = 0; i < dst->height; i++){
for(int j = 0; j < dst->width; j++){
B = (unsigned char)src->imageData[(j * 3) + i * src->widthStep];
G = (unsigned char)src->imageData[(j * 3) + i * src->widthStep + 1];
R = (unsigned char)src->imageData[(j * 3) + i * src->widthStep + 2];
bool a = R1(R,G,B);
if(a){
H = (unsigned char)img_HSV->imageData[(j * 3) + i * img_HSV->widthStep];
S = (unsigned char)img_HSV->imageData[(j * 3) + i * img_HSV->widthStep + 1];
V = (unsigned char)img_HSV->imageData[(j * 3) + i * img_HSV->widthStep + 2];
bool c = R3(H,S,V);;
if(c){
Y = (unsigned char)img_YCrCb->imageData[(j * 3) + i * img_YCrCb->widthStep];
Cr = (unsigned char)img_YCrCb->imageData[(j * 3) + i * img_YCrCb->widthStep + 1];
Cb = (unsigned char)img_YCrCb->imageData[(j * 3) + i * img_YCrCb->widthStep + 2];
bool b = R2(Y,Cr,Cb);
if(b)
dst->imageData[j + i * dst->widthStep] = (unsigned char) 255;
}
}
}
}
cvErode(dst, dst, 0, MOP_NUM);
cvDilate(dst, dst, 0, MOP_NUM);
}
示例2: cvResizeDsize
void GripPipeline::Process(cv::Mat & source0)
{
cv::Mat cvResizeSrc = source0;
cv::Size cvResizeDsize(0, 0);
double cvResizeFx = 0.75; // default Double
double cvResizeFy = 0.75; // default Double
int cvResizeInterpolation = cv::INTER_LINEAR;
cvResize(cvResizeSrc, cvResizeDsize, cvResizeFx, cvResizeFy, cvResizeInterpolation, this->cvResizeOutput);
cv::Mat hsvThresholdInput = cvResizeOutput;
double hsvThresholdHue[] = {69,180};
double hsvThresholdSaturation[] = {172,255};
double hsvThresholdValue[] = {112,255};
hsvThreshold(hsvThresholdInput, hsvThresholdHue, hsvThresholdSaturation, hsvThresholdValue, this->hsvThresholdOutput);
cv::Mat findContoursInput = hsvThresholdOutput;
source0= hsvThresholdOutput;
std::vector<std::vector<cv::Point> > filterContoursContours = findContoursOutput;
cv::Mat cvErodeSrc = hsvThresholdOutput;
cv::Mat cvErodeKernel;
cv::Point cvErodeAnchor(-1, -1);
double cvErodeIterations = 1;
int cvErodeBordertype = cv::BORDER_CONSTANT;
cv::Scalar cvErodeBordervalue(-1);
cvErode(cvErodeSrc, cvErodeKernel, cvErodeAnchor, cvErodeIterations, cvErodeBordertype, cvErodeBordervalue, this->cvErodeOutput);
cv::Mat findLinesInput = cvErodeOutput;
findLines(findLinesInput, this->findLinesOutput);
// print the lines
// GripPipeline::printLines(source0, findLinesOutput);
// find center
GripPipeline::findCenter(source0, findLinesOutput);
// find distance
GripPipeline::findDistance(source0, findLinesOutput, difference);
}
示例3: givedepth
void givedepth(IplImage *localimagergb)
{ IplImage*localimage=cvCreateImage(cvGetSize(localimagergb),IPL_DEPTH_8U,3);
cvCvtColor(localimagergb,localimage,CV_BGR2HSV);
IplImage *blobbedscaling=cvCreateImage(cvGetSize(localimagergb),IPL_DEPTH_8U,3);
uchar *itemp=(uchar *)(localimage->imageData);
IplImage *binaryscaling=cvCreateImage(cvGetSize(localimagergb),IPL_DEPTH_8U,1);
uchar *itemp1=(uchar *)(binaryscaling ->imageData);
for(int i=0;i<hi2->height;i++){
for(int j=0;j<hi2->width;j++){
if((itemp[i*localimage->widthStep+j*localimage->nChannels] <hh)
&&
(itemp[i*localimage->widthStep+j*localimage->nChannels]>hl)
&&
(itemp[i*localimage->widthStep+j*localimage->nChannels+1]<sh)
&&
(itemp[i*localimage->widthStep+j*localimage->nChannels+1]>sl)
&&
( itemp[i*localimage->widthStep+j*localimage->nChannels+2]<vh)
&&
( itemp[i*localimage->widthStep+j*localimage->nChannels+2]>vl) //previous 124
) {
itemp1[i*binaryscaling->widthStep+j]=0; //dark regions black rest white
}
else
itemp1[i*binaryscaling->widthStep+j]=255;
}}
cvErode( binaryscaling, binaryscaling, NULL, 4);
cvDilate(binaryscaling, binaryscaling, NULL, 4);
CBlobResult blob;
CBlob *currentBlob=NULL;
blob=CBlobResult(binaryscaling,NULL,255);
blob.Filter(blob,B_EXCLUDE,CBlobGetArea(),B_LESS,500);
cvMerge(binaryscaling,binaryscaling,binaryscaling,NULL,blobbedscaling);
CBlob hand1,hand2; //two blobs,one for each hand
blob.GetNthBlob( CBlobGetArea(), 0, (hand2));
blob.GetNthBlob( CBlobGetArea(), 1, (hand1 ));
hand1.FillBlob(blobbedscaling,CV_RGB(0,0,255)); //fill the color of blob of hand one with blue
hand2.FillBlob(blobbedscaling,CV_RGB(0,255,0)); //fill the color of blob of hand two with green
coordinates (blobbedscaling,0);
}
示例4: cvCreateImage
void clsTracking2D::calcBGsubtraction(IplImage *image, IplImage *foreground, IplImage *debugImage)
{
if(!BGcolorstarted)
{
bgcolorImage = cvCreateImage( cvSize( image->width, image->height ),image->depth, image->nChannels );
bgsGray = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
cvCvtColor(image, bgsGray, CV_BGR2GRAY);
readyForParticles = true;
BGcolorstarted = true;
}
cvCopy(image,bgcolorImage);
if(paramsInt["blur"] > 0)
cvSmooth(image, bgcolorImage, CV_BLUR, paramsInt["blur"], paramsInt["blur"], 0, 0);
//converting to HSV
// cvCvtColor(bgcolorImage, bgcolorImage, CV_BGR2HSV);
//filtrating by color... good on this video!
cvInRangeS(bgcolorImage, cvScalar(paramsInt["minH"], paramsInt["minS"], paramsInt["minL"]), cvScalar(paramsInt["maxH"], paramsInt["maxS"], paramsInt["maxL"]), foreground);
// cv::invert(bgcolorImage,bgcolorImage);
// cvCvtColor(bgcolorImage, bgsGray, CV_BGR2GRAY);
// cvThreshold(bgsGray, foreground, paramsInt["minThreshold"], paramsInt["maxThreshold"], CV_THRESH_BINARY );
// cvThreshold(bgsGray, foreground, paramsInt["minThreshold"], paramsInt["maxThreshold"], CV_THRESH_BINARY);
// cvThreshold(bgsGray, foreground, paramsInt["minThreshold"], paramsInt["maxThreshold"], CV_THRESH_BINARY_INV);
// cvThreshold(foreground, foreground, 5,255, 1 );
//removing loose points
cvErode(foreground, foreground, NULL,1);
//augmenting neighbour points
cvDilate(foreground, foreground, NULL,1);
//calculating edges
// cvCanny(foreground,foreground,10,100,3);
}
示例5: cvResizeDsize
/**
* Runs an iteration of the Pipeline and updates outputs.
*
* Sources need to be set before calling this method.
*
*/
void GripPipeline::process(cv::Mat source0){
//Step CV_resize0:
//input
cv::Mat cvResizeSrc = source0;
cv::Size cvResizeDsize(0, 0);
double cvResizeFx = 0.25; // default Double
double cvResizeFy = 0.25; // default Double
int cvResizeInterpolation = cv::INTER_LINEAR;
cvResize(cvResizeSrc, cvResizeDsize, cvResizeFx, cvResizeFy, cvResizeInterpolation, this->cvResizeOutput);
//Step HSV_Threshold0:
//input
cv::Mat hsvThresholdInput = cvResizeOutput;
double hsvThresholdHue[] = {42.086330935251794, 86.7911714770798};
double hsvThresholdSaturation[] = {32.10431654676259, 207.37691001697794};
double hsvThresholdValue[] = {91.72661870503596, 255.0};
hsvThreshold(hsvThresholdInput, hsvThresholdHue, hsvThresholdSaturation, hsvThresholdValue, this->hsvThresholdOutput);
//Step CV_erode0:
//input
cv::Mat cvErodeSrc = hsvThresholdOutput;
cv::Mat cvErodeKernel;
cv::Point cvErodeAnchor(-1, -1);
double cvErodeIterations = 1; // default Double
int cvErodeBordertype = cv::BORDER_CONSTANT;
cv::Scalar cvErodeBordervalue(-1);
cvErode(cvErodeSrc, cvErodeKernel, cvErodeAnchor, cvErodeIterations, cvErodeBordertype, cvErodeBordervalue, this->cvErodeOutput);
//Step Mask0:
//input
cv::Mat maskInput = cvResizeOutput;
cv::Mat maskMask = cvErodeOutput;
mask(maskInput, maskMask, this->maskOutput);
//Step Find_Blobs0:
//input
cv::Mat findBlobsInput = maskOutput;
double findBlobsMinArea = 0.0; // default Double
double findBlobsCircularity[] = {0.0, 1.0};
bool findBlobsDarkBlobs = true; // default Boolean
findBlobs(findBlobsInput, findBlobsMinArea, findBlobsCircularity, findBlobsDarkBlobs, this->findBlobsOutput);
}
示例6: main
int main( int argc, char** argv )
{
//Check if user specify image to process
if(argc >= 2 )
{
char* filename= argv[1];
//load image in gray level
imagen=cvLoadImage(filename,0);
}
else
{
printf("Use:\n\t%s image\n",argv[0]);
return 0;
}
//------------------------------------------------------------------------------------
//NUMBER ISOLATION
//Create needed images
smooth= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
threshold= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
open_morf= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
cvSmooth(imagen, smooth, CV_GAUSSIAN, 3, 0, 0, 0);
CvScalar avg;
CvScalar avgStd;
cvAvgSdv(smooth, &avg, &avgStd, NULL);
//printf("Avg: %f\nStd: %f\n", avg.val[0], avgStd.val[0]);
//threshold image
cvThreshold(smooth, threshold, (int)avg.val[0]+4*(int)(avgStd.val[0]/8), 255, CV_THRESH_BINARY);
//Morfologic filters
cvErode(threshold, open_morf, NULL,1);
cvDilate(open_morf, open_morf, NULL,1);
int lprs=cvSaveImage(argv[2],open_morf,&lprs);
//Duplicate image for countour
cvReleaseImage(&imagen);
cvReleaseImage(&open_morf);
return 0;
}
示例7: cutterDetect
IplImage* cutterDetect(IplImage *img) {
// Convert the image into an HSV image
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
// Create an image for the output
IplImage* out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
IplImage *temp = cvCreateImage(cvSize(img->width,img->height),8,1);
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
// Perform a Gaussian blur
cvSmooth( img, out, CV_GAUSSIAN,15, 15);
cvCvtColor(out, imgHSV, CV_BGR2HSV);
cvInRangeS(imgHSV, BLUE_LOW, BLUE_HIGH, imgThreshed);
cvErode(imgThreshed,temp,NULL,1);
cvDilate(temp,imgThreshed,NULL,1);
cvReleaseImage(&imgHSV);
cvReleaseImage(&temp);
cvReleaseImage( &out );
return imgThreshed;
}
示例8: node_composit_exec_cvErode
static void node_composit_exec_cvErode(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
int iterations;
IplImage *src, *dst;
CompBuf *dst_buf;
if(in[0]->hasinput==0) return;
if(out[0]->hasoutput==0) return;
src= BOCV_IplImage_attach(in[0]->data);
dst_buf = dupalloc_compbuf(in[0]->data);
iterations=(int)in[1]->vec[0];
dst = BOCV_IplImage_attach(dst_buf);
cvErode(src,dst,0,iterations);
out[0]->data = dst_buf;
BOCV_IplImage_detach(src);
BOCV_IplImage_detach(dst);
}
示例9: x
int regionTracker::calcCentroidAndArea()
{
// input: none
// output: set centroid and area, CvPoint and int
// return: 0
//
// Calculate controid and area of region
int areaCount = 0; // count total pixel of region
int xSum = 0, ySum = 0; // sum of x (or y) coordinate of each pixel in the region
CvScalar current;
int i, j;
int iteration = 5;
// contract 'result' for reduce influence by arm when calcurate centroid
cvErode (result, contractedResult, element, iteration);
for(i=0; i<result->width; i++)
for(j=0; j<result->height; j++)
{
current = cvGet2D(contractedResult, j, i);
if(current.val[0] != 0)
{
areaCount++;
xSum += i;
ySum += j;
}
}
// set result
if(areaCount == 0) return -1;
area = areaCount;
centroid.x = xSum / areaCount;
centroid.y = ySum / areaCount;
return 0;
}
示例10: if
int regionDetector::getRegion(IplImage *src, int x, int y, IplImage *dst)
{
// input: image (depth, intensity and so on), IplImage, 1 channel, (recommend 8 bit depth)
// a coordinate which is contained in region you want to get, int
// return: region image, IplImage, binary image
// or 0 if coordinate is invalid (out of iamge size or there are no region)
//
// Take (depth, intensity, binary and so on) image, classify the image by the region.
// The region is pixels which has almost same value between that pixel and around pixels.
// And return the region which contain pixel (x, y).
int bitDepth;
int iteration;
// prepare images
original = src;
result->imageData = dst->imageData;
// set threshold value.
bitDepth = src->depth;
if(bitDepth == IPL_DEPTH_8U)
threshold = 20;
else if(bitDepth == IPL_DEPTH_16U)
threshold = 4000;
else
return 0;
// get region
traverse(x, y, NONE);
// noise reduction
iteration = 2;
cvErode (dst, dst, element, iteration);
cvDilate (dst, dst, element, iteration);
return 0;
}
示例11: cvCalcMotionGradient
CV_IMPL void
cvCalcMotionGradient( const CvArr* mhiimg, CvArr* maskimg,
CvArr* orientation,
double delta1, double delta2,
int aperture_size )
{
cv::Ptr<CvMat> dX_min, dY_max;
CvMat mhistub, *mhi = cvGetMat(mhiimg, &mhistub);
CvMat maskstub, *mask = cvGetMat(maskimg, &maskstub);
CvMat orientstub, *orient = cvGetMat(orientation, &orientstub);
CvMat dX_min_row, dY_max_row, orient_row, mask_row;
CvSize size;
int x, y;
float gradient_epsilon = 1e-4f * aperture_size * aperture_size;
float min_delta, max_delta;
if( !CV_IS_MASK_ARR( mask ))
CV_Error( CV_StsBadMask, "" );
if( aperture_size < 3 || aperture_size > 7 || (aperture_size & 1) == 0 )
CV_Error( CV_StsOutOfRange, "aperture_size must be 3, 5 or 7" );
if( delta1 <= 0 || delta2 <= 0 )
CV_Error( CV_StsOutOfRange, "both delta's must be positive" );
if( CV_MAT_TYPE( mhi->type ) != CV_32FC1 || CV_MAT_TYPE( orient->type ) != CV_32FC1 )
CV_Error( CV_StsUnsupportedFormat,
"MHI and orientation must be single-channel floating-point images" );
if( !CV_ARE_SIZES_EQ( mhi, mask ) || !CV_ARE_SIZES_EQ( orient, mhi ))
CV_Error( CV_StsUnmatchedSizes, "" );
if( orient->data.ptr == mhi->data.ptr )
CV_Error( CV_StsInplaceNotSupported, "orientation image must be different from MHI" );
if( delta1 > delta2 )
{
double t;
CV_SWAP( delta1, delta2, t );
}
size = cvGetMatSize( mhi );
min_delta = (float)delta1;
max_delta = (float)delta2;
dX_min = cvCreateMat( mhi->rows, mhi->cols, CV_32F );
dY_max = cvCreateMat( mhi->rows, mhi->cols, CV_32F );
// calc Dx and Dy
cvSobel( mhi, dX_min, 1, 0, aperture_size );
cvSobel( mhi, dY_max, 0, 1, aperture_size );
cvGetRow( dX_min, &dX_min_row, 0 );
cvGetRow( dY_max, &dY_max_row, 0 );
cvGetRow( orient, &orient_row, 0 );
cvGetRow( mask, &mask_row, 0 );
// calc gradient
for( y = 0; y < size.height; y++ )
{
dX_min_row.data.ptr = dX_min->data.ptr + y*dX_min->step;
dY_max_row.data.ptr = dY_max->data.ptr + y*dY_max->step;
orient_row.data.ptr = orient->data.ptr + y*orient->step;
mask_row.data.ptr = mask->data.ptr + y*mask->step;
cvCartToPolar( &dX_min_row, &dY_max_row, 0, &orient_row, 1 );
// make orientation zero where the gradient is very small
for( x = 0; x < size.width; x++ )
{
float dY = dY_max_row.data.fl[x];
float dX = dX_min_row.data.fl[x];
if( fabs(dX) < gradient_epsilon && fabs(dY) < gradient_epsilon )
{
mask_row.data.ptr[x] = 0;
orient_row.data.i[x] = 0;
}
else
mask_row.data.ptr[x] = 1;
}
}
cvErode( mhi, dX_min, 0, (aperture_size-1)/2);
cvDilate( mhi, dY_max, 0, (aperture_size-1)/2);
// mask off pixels which have little motion difference in their neighborhood
for( y = 0; y < size.height; y++ )
{
dX_min_row.data.ptr = dX_min->data.ptr + y*dX_min->step;
dY_max_row.data.ptr = dY_max->data.ptr + y*dY_max->step;
mask_row.data.ptr = mask->data.ptr + y*mask->step;
orient_row.data.ptr = orient->data.ptr + y*orient->step;
for( x = 0; x < size.width; x++ )
{
float d0 = dY_max_row.data.fl[x] - dX_min_row.data.fl[x];
if( mask_row.data.ptr[x] == 0 || d0 < min_delta || max_delta < d0 )
{
mask_row.data.ptr[x] = 0;
//.........这里部分代码省略.........
示例12: erode_end_frame_filter
static void erode_end_frame_filter(AVFilterContext *ctx, IplImage *inimg, IplImage *outimg)
{
OCVContext *ocv = ctx->priv;
DilateContext *dilate = ocv->priv;
cvErode(inimg, outimg, dilate->kernel, dilate->nb_iterations);
}
示例13: findSquares4
// returns sequence of squares detected on the image.
// the sequence is stored in the specified memory storage
CvSeq* findSquares4( IplImage* img, CvMemStorage* &storage,bool isForDay)
{
CvSeq* contours;
int i, l, N = 50;
int thresh2,thresh1=15;
if(isForDay) {
thresh2=240;}
else {thresh2=180;}
CvSize sz = cvSize( img->width & -2, img->height & -2 );
IplImage* timg = cvCloneImage( img ); // make a copy of input image
IplImage* gray = cvCreateImage( cvGetSize(timg), 8, 1 );
//IplImage* pyr = cvCreateImage( cvSize(sz.width/2, sz.height/2), 8, 3 );
IplImage* tgray;
CvSeq* result;
double s, t;
// storage=cvCreateMemStorage(0);
// create empty sequence that will contain points -
// 4 points per square (the square's vertices)
CvSeq* squares = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvPoint), storage );
// select the maximum ROI in the image
// with the width and height divisible by 2
cvSetImageROI( timg, cvRect( 0, 0, sz.width, sz.height ));
// down-scale and upscale the image to filter out the noise
// cvPyrDown( timg, pyr, 7 );
// cvPyrUp( pyr, timg, 7 );
tgray = cvCreateImage( sz, 8, 1 );
// cvCvtColor(timg,timg,CV_BGR2HSV);
// cvCvtColor(timg,tgray,CV_HSV2GRAY);
// cvShowImage("tg",tgray);
// find squares in every color plane of the image
for(int c = 0; c < 3; c++ )
{
// cout<<c<<endl;
// extract the c-th color plane
cvSetImageCOI( timg, c+1 );
cvCopy( timg, tgray, 0 );
// cvEqualizeHist(tgray,tgray);
// try several threshold levels
for( l = 0; l < N; l++ )
{
// hack: use Canny instead of zero thres50hold level.
// Canny helps to catch squares with gradient shading
if( l == 0 )
{
// apply Canny. Take the upper threshold from slider
// and set the lower to 0 (which forces edges merging)
cvCanny( tgray, gray,thresh1, thresh2, 3 ); // 白天
// cvCanny( tgray, gray,15, 240, 3 );
// ImagePreprocess::colorEdgeDetect1(img,gray,15,240);
// dilate canny output to remove potential
// holes between edge segments
cvDilate( gray, gray, 0, 1 );
cvErode( gray, gray, 0, 1 );
}
else
{
//apply threshold if l!=0:
cvThreshold( tgray, gray, (l+1)*255/N, 255, CV_THRESH_BINARY );
// cvShowImage("gray",gray);
}
// find contours and store them all as a list
cvFindContours( gray, storage, &contours, sizeof(CvContour),
CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) );
// test each contour
while( contours )
{
// approximate contour with accuracy proportional
// to the contour perimeter
result = cvApproxPoly( contours, sizeof(CvContour), storage,
CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0 );
// square contours should have 4 vertices after approximation
// relatively large area (to filter out noisy contours)
// and be convex.
// Note: absolute value of an area is used because
// area may be positive or negative - in accordance with the
// contour orientation
if( result->total == 4 &&
fabs(cvContourArea(result,CV_WHOLE_SEQ)) > 4000 &&
fabs(cvContourArea(result,CV_WHOLE_SEQ)) < 10000 &&
cvCheckContourConvexity(result) )
{
s = 0;
for( i = 0; i < 5; i++ )
{
// find minimum angle between joint
// edges (maximum of cosine)
if( i >= 2 )
{
t = fabs(angle(
//.........这里部分代码省略.........
示例14: get_fish_pos
void get_fish_pos(){
mod++;
if(g_msPrm.isDrawing){
cvCopy(frame,cl_frame,NULL);
switch(g_mouse){
case AVG_POS:
set_avg_pos(cl_frame);
break;
case RANGE_POS:
set_range_pos(cl_frame);
break;
default:
break;
}
}
else{
frame = cvQueryFrame( g_capture );
// if(!(++mod&0x3))
// cvShowImage("Camera",frame);
#if 1
// if(g_msPrm.box.width != 0){
// draw_box(frame,g_msPrm.box);
// }
// else{
// }
cvCircle(frame,
fishPos,
sqrt(mom.m00)/1,
cvScalar(0x00,0x00,0x00,0),1,8,0
);
//if(!(++mod&0x3))
cvShowImage("Camera",frame);
if(g_is_range){
cvSetImageROI(frame,g_range);
cvSetZero(gr_frame);
cvSetImageROI(gr_frame,g_range);
}
cvSmooth( frame, frame, CV_GAUSSIAN, 3, 3 ,0,0);
//cvCvtColor(frame,frame,CV_RGB2HSV);
cvInRangeS(frame,g_hsv_min,g_hsv_max,gr_frame);
if(g_is_range){
cvSetImageROI(frame,g_range);
}
cvErode(gr_frame,gr_frame,NULL,2);
cvDilate(gr_frame,gr_frame,NULL,2);
if(g_is_range){
cvResetImageROI(frame);
cvResetImageROI(gr_frame);
}
cvMoments(gr_frame,&mom,1);
fishPos.x = (mom.m10/mom.m00);
fishPos.y = (mom.m01/mom.m00);
cvShowImage( "set_HSV", gr_frame );
// cvErode(gr_frame,gr_frame,NULL,10);
#endif
}
}
示例15: gst_gcs_transform_ip
static GstFlowReturn gst_gcs_transform_ip(GstBaseTransform * btrans, GstBuffer * gstbuf)
{
GstGcs *gcs = GST_GCS (btrans);
GST_GCS_LOCK (gcs);
//////////////////////////////////////////////////////////////////////////////
// get image data from the input, which is RGBA or BGRA
gcs->pImageRGBA->imageData = (char*)GST_BUFFER_DATA(gstbuf);
cvSplit(gcs->pImageRGBA, gcs->pImgCh1, gcs->pImgCh2, gcs->pImgCh3, gcs->pImgChX );
cvCvtColor(gcs->pImageRGBA, gcs->pImgRGB, CV_BGRA2BGR);
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////MOTION CUES INTEGR////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// apply step 1. filtering using bilateral filter. Cannot happen in-place => scratch
cvSmooth(gcs->pImgRGB, gcs->pImgScratch, CV_BILATERAL, 3, 50, 3, 0);
// create GRAY image
cvCvtColor(gcs->pImgScratch, gcs->pImgGRAY, CV_BGR2GRAY);
// Frame difference the GRAY and the previous one
// not intuitive: first smooth frames, then
cvCopy( gcs->pImgGRAY, gcs->pImgGRAY_copy, NULL);
cvCopy( gcs->pImgGRAY_1, gcs->pImgGRAY_1copy, NULL);
get_frame_difference( gcs->pImgGRAY_copy, gcs->pImgGRAY_1copy, gcs->pImgGRAY_diff);
cvErode( gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, NULL, 3);
cvDilate( gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, NULL, 3);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// ghost mapping
gcs->dstTri[0].x = gcs->facepos.x - gcs->facepos.width/2 ;
gcs->dstTri[0].y = gcs->facepos.y - gcs->facepos.height/2;
gcs->dstTri[1].x = gcs->facepos.x - gcs->facepos.width/2;
gcs->dstTri[1].y = gcs->facepos.y + gcs->facepos.height/2;
gcs->dstTri[2].x = gcs->facepos.x + gcs->facepos.width/2;
gcs->dstTri[2].y = gcs->facepos.y + gcs->facepos.height/2;
if( gcs->ghostfilename){
cvGetAffineTransform( gcs->srcTri, gcs->dstTri, gcs->warp_mat );
cvWarpAffine( gcs->cvGhostBwResized, gcs->cvGhostBwAffined, gcs->warp_mat );
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// GrabCut algorithm preparation and running
gcs->facepos.x = gcs->facepos.x - gcs->facepos.width/2;
gcs->facepos.y = gcs->facepos.y - gcs->facepos.height/2;
// create an IplImage with the skin colour pixels as 255
compose_skin_matrix(gcs->pImgRGB, gcs->pImg_skin);
// And the skin pixels with the movement mask
cvAnd( gcs->pImg_skin, gcs->pImgGRAY_diff, gcs->pImgGRAY_diff);
//cvErode( gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, cvCreateStructuringElementEx(5, 5, 3, 3, CV_SHAPE_RECT,NULL), 1);
cvDilate(gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, cvCreateStructuringElementEx(7,7, 5,5, CV_SHAPE_RECT,NULL), 2);
cvErode( gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, cvCreateStructuringElementEx(5,5, 3,3, CV_SHAPE_RECT,NULL), 2);
// if there is alpha==all 1's coming in, then we ignore it: prevents from no vibe before us
if((0.75*(gcs->width * gcs->height) <= cvCountNonZero(gcs->pImgChX)))
cvZero(gcs->pImgChX);
// OR the input Alpha
cvOr( gcs->pImgChX, gcs->pImgGRAY_diff, gcs->pImgGRAY_diff);
//////////////////////////////////////////////////////////////////////////////
// try to consolidate a single mask from all the sub-patches
cvDilate(gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, cvCreateStructuringElementEx(7,7, 5,5, CV_SHAPE_RECT,NULL), 3);
cvErode( gcs->pImgGRAY_diff, gcs->pImgGRAY_diff, cvCreateStructuringElementEx(5,5, 3,3, CV_SHAPE_RECT,NULL), 4);
//////////////////////////////////////////////////////////////////////////////
// use either Ghost or boxes-model to create a PR foreground starting point in gcs->grabcut_mask
if( gcs->ghostfilename)
compose_grabcut_seedmatrix3(gcs->grabcut_mask, gcs->cvGhostBwAffined, gcs->pImgGRAY_diff );
else{
// toss it all to the bbox creation function, together with the face position and size
compose_grabcut_seedmatrix2(gcs->grabcut_mask, gcs->facepos, gcs->pImgGRAY_diff, gcs->facefound );
}
//////////////////////////////////////////////////////////////////////////////
#ifdef KMEANS
gcs->num_clusters = 18; // keep it even to simplify integer arithmetics
cvCopy(gcs->pImgRGB, gcs->pImgRGB_kmeans, NULL);
posterize_image(gcs->pImgRGB_kmeans);
create_kmeans_clusters(gcs->pImgRGB_kmeans, gcs->kmeans_points, gcs->kmeans_clusters,
gcs->num_clusters, gcs->num_samples);
adjust_bodybbox_w_clusters(gcs->grabcut_mask, gcs->pImgRGB_kmeans, gcs->num_clusters, gcs->facepos);
#endif //KMEANS
//////////////////////////////////////////////////////////////////////////////
if( gcs->debug < 70)
//.........这里部分代码省略.........