本文整理汇总了C++中CBlobResult类的典型用法代码示例。如果您正苦于以下问题:C++ CBlobResult类的具体用法?C++ CBlobResult怎么用?C++ CBlobResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CBlobResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNearestBlob
CBlob getNearestBlob(CBlobResult blobs, coord coordinate){
int tot = blobs.GetNumBlobs();
CBlob Blob;
float distance[10]; // 10 è il numero massimo di blob trovabile in un video
float minimum;
coord tempCoord;
//Questo ciclo for fa la distanza manhattan tra le coordinate passate e tutti i blob catturati e crea il vettore con tutte le distanze.
for (int i=0; i<tot; i++){
Blob = blobs.GetBlob(i);
tempCoord.set( (int) Blob.MaxX(), (int) Blob.MinX(), (int) Blob.MaxY(), (int) Blob.MinY());
distance[i] = sqrt((double)(tempCoord.cX - coordinate.cX)*(tempCoord.cX - coordinate.cX) + (tempCoord.cY - coordinate.cY)*(tempCoord.cY - coordinate.cY));
}
int minDistanceId=0;
//Questo ciclo for becca la minima distanza fra tutte quelle calcolate
for (int j=0; j<tot; j++){
minimum = min( distance[j], distance[minDistanceId]);
if ( distance[j] == minimum ) minDistanceId = j;
}
//Ottenuta la minima distanza si va a ritornare il Blob corrispondente
Blob = blobs.GetBlob( minDistanceId );
//delete[] distance;
return Blob;
}
示例2: CBlobResult
/* Detect blobs larger than min_size in a given IplImage. */
CBlobResult MarkerCapture::detect_blobs(IplImage *img, int min_size = 10){
// find white blobs in thresholded image
CBlobResult blobs = CBlobResult(img, NULL, 0);
// exclude ones smaller than min_size.
blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, min_size);
return blobs;
}
示例3: cvLoadImage
void ScheinrieseApp::findBlobs() {
CBlobResult blobs;
int i;
CBlob *currentBlob;
IplImage *original, *originalThr;
// load an image and threshold it
original = cvLoadImage("pic1.png", 0);
cvThreshold( original, originalThr, 100, 0, 255, CV_THRESH_BINARY );
// find non-white blobs in thresholded image
blobs = CBlobResult( originalThr, NULL, 255 );
// exclude the ones smaller than param2 value
blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );
// get mean gray color of biggest blob
CBlob biggestBlob;
CBlobGetMean getMeanColor( original );
double meanGray;
blobs.GetNth( CBlobGetArea(), 0, biggestBlob );
meanGray = getMeanColor( biggestBlob );
// display filtered blobs
cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );
for (i = 0; i < blobs.GetNumBlobs(); i++ )
{
currentBlob = blobs.GetBlob(i);
currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
}
}
示例4: Mat
void ForegroundDetector::nextIteration(const Mat &img)
{
if(bgImg.empty())
{
return;
}
Mat absImg = Mat(img.cols, img.rows, img.type());
Mat threshImg = Mat(img.cols, img.rows, img.type());
absdiff(bgImg, img, absImg);
threshold(absImg, threshImg, fgThreshold, 255, CV_THRESH_BINARY);
IplImage im = (IplImage)threshImg;
CBlobResult blobs = CBlobResult(&im, NULL, 0);
blobs.Filter(blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, minBlobSize);
vector<Rect>* fgList = detectionResult->fgList;
fgList->clear();
for(int i = 0; i < blobs.GetNumBlobs(); i++)
{
CBlob *blob = blobs.GetBlob(i);
CvRect rect = blob->GetBoundingBox();
fgList->push_back(rect);
}
}
示例5: drawInitialBlobs
void drawInitialBlobs(IplImage * tmp_frame, CBlobResult blobs){
coord drawCoord;
for (int i=0; i<blobs.GetNumBlobs();i++){
//!Creating the coordinate struct
drawCoord.set( (int) blobs.GetBlob(i).MaxX(), (int) blobs.GetBlob(i).MinX(), (int) blobs.GetBlob(i).MaxY(), (int) blobs.GetBlob(i).MinY());
drawBlob(tmp_frame, drawCoord, 255, 255, 0);
}
}
示例6: tick
/* Fetch a frame (if available) and process it, calling appropriate
callbacks when data becomes available. */
void MarkerCapture::tick(){
IplImage *thresh_frame = NULL;
CBlobResult blobs;
// Acquire the lock, update the current frame.
pthread_mutex_lock(&frame_mutex);
current_frame = cvCloneImage(cvQueryFrame(camera));
if(color_acquired && current_frame){
thresh_frame = apply_threshold(current_frame, target_color);
}else{
// create a suplicant.
thresh_frame = cvCreateImage(cvGetSize(current_frame),IPL_DEPTH_8U,1);
}
pthread_mutex_unlock(&frame_mutex);
// Lock released. Done messing with buffers.
if(frame_update_callback){
(*frame_update_callback)(this, current_frame, thresh_frame);
}
if(color_acquired){
blobs = detect_blobs(thresh_frame, CV_BLOB_SIZE_MIN);
if(blobs.GetNumBlobs() >= 2){ // need 2 or more blobs for positional fix.
MarkerPositionEstimate position;
// fetch the two largest blobs, by area.
CBlob blob0, blob1;
blobs.GetNthBlob(CBlobGetArea(), 0, blob0);
blobs.GetNthBlob(CBlobGetArea(), 1, blob1);
// perform positional calculations
position.distance = distance(blob0, blob1);
position.angle = angle(blob0, blob1);
position.blob0_center = blob_center(blob0);
position.blob1_center = blob_center(blob1);
// call the update handler.
if(position_update_callback){
(*position_update_callback)(this, position);
}
}
blobs.ClearBlobs();
}
pthread_mutex_lock(&frame_mutex);
cvReleaseImage(¤t_frame);
cvReleaseImage(&thresh_frame);
pthread_mutex_unlock(&frame_mutex);
int curr_time = clock();
fps = CLOCKS_PER_SEC/(double)(curr_time - time);
time = curr_time;
}
示例7: cvRect
vector<Bubble> OMRSheet::getBubbles(int xi1, int yi1, int xi2, int yi2){
vector <Bubble> bubbles;
cout<<"Bubble area "<<bubbleArea;
int minArea = bubbleArea/2, maxArea = bubbleArea*1.5;
CBlobResult blobs = ImageUtils::findBlobs(rawSheet, minArea, maxArea, cvRect(xi1, yi1, xi2-xi1, yi2-yi1));
for (int i = 0; i < blobs.GetNumBlobs(); i++ )
{
CvRect rect = blobs.GetBlob(i)->GetBoundingBox();
Point centroid = ImageUtils::findCentroid(rawSheet, &rect);
Point centroidMM((centroid.x() - x1)/15, (centroid.y() - y1)/15);
Bubble bubble(blobs.GetBlob(i), ¢roidMM, ¢roid);
bubbles.push_back(bubble);
}
return bubbles;
}
示例8: extractBots
void extractBots()
{
//RED TEAM
imgTransform(TEAM_R_HUE_U, TEAM_R_HUE_L, TEAM_R_SAT_U, TEAM_R_SAT_L, VAL_U, VAL_L);
blobRes = CBlobResult(dst, NULL, 0);
blobRes.Filter( blobRes, B_EXCLUDE, CBlobGetArea(), B_LESS, BLOB_SIZE_MIN );// keep blobs larger than BLOB_SIZE_MIN
numOfBlobs = blobRes.GetNumBlobs(); cout << numOfBlobs << endl;
if(numOfBlobs == 2)
{
for (int i=0; i<2; i++)
blobRes.GetBlob(i)
for(int i=0; i<numOfBlobs; i++)
blobs[i] = blobRes.GetBlob(i);
};
void printBlobs()
{
CBlobGetXCenter getXC;
CBlobGetYCenter getYC;
CBlobGetArea getArea;
CBlobGetCompactness getCompactness;
printf("-----Printng Blobs------\n");
for(int i=0; i<numOfBlobs; i++)
{
printf("%d\t(%3.2f,%3.2f),%3.2f %3.2f\n", i, getXC(blobs[i]), getYC(blobs[i]), getArea(blobs[i]), getCompactness(blobs[i]));
}
printf("\n");
cvNamedWindow("old", 1);
cvNamedWindow("new", 1);
cvMoveWindow("old", 0,0);
cvMoveWindow("new", 0,400);
cvShowImage("old", img);
cvShowImage("new", dst);
cvWaitKey();
};
示例9: while
/**
- FUNCTION: CBlobResult
- FUNCTIONALITY: Copy constructor
- PARAMETERS:
- source: object to copy
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
CBlobResult::CBlobResult( const CBlobResult &source )
{
m_blobs = blob_vector( source.GetNumBlobs() );
// creem el nou a partir del passat com a paràmetre
m_blobs = blob_vector( source.GetNumBlobs() );
// copiem els blobs de l'origen a l'actual
blob_vector::const_iterator pBlobsSrc = source.m_blobs.begin();
blob_vector::iterator pBlobsDst = m_blobs.begin();
while( pBlobsSrc != source.m_blobs.end() )
{
// no podem cridar a l'operador = ja que blob_vector és un
// vector de CBlob*. Per tant, creem un blob nou a partir del
// blob original
*pBlobsDst = new CBlob(**pBlobsSrc);
pBlobsSrc++;
pBlobsDst++;
}
}
示例10: 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);
}
示例11: getBlobs
CBlobResult getBlobs(IplImage* tmp_frame, IplImage* binFore){
//IplImage* binFore = cvCreateImage(cvGetSize(tmp_frame),IPL_DEPTH_8U,1);
//get the binary foreground object
//cvSub( getBinaryImage(tmp_frame) , binBack, binFore, NULL );
//if(!cvSaveImage("binFore.jpg",binFore)) printf("Could not save the backgroundimage\n");
//!Starting the extracting of Blob
CBlobResult blobs;
//! get the blobs from the image, with no mask, using a threshold of 100
blobs = CBlobResult( binFore, NULL, 10, true );
//! Create a file with all the found blob
blobs.PrintBlobs( "blobs.txt" );
//! discard the blobs with less area than 60 pixels
blobs.Filter( blobs, B_INCLUDE, CBlobGetArea(), B_GREATER, 40);
//!This two row of code are to filter the blob find from the library by a bug that match ablob like all the image and return the center of it
blobs.Filter( blobs, B_INCLUDE, CBlobGetArea(), B_LESS, (tmp_frame->height)*(tmp_frame->width)*0.8);
blobs.Filter( blobs, B_INCLUDE, CBlobGetPerimeter(), B_LESS, (tmp_frame->height)+(tmp_frame->width)*2*0.8);
//! Create a file with filtered results
blobs.PrintBlobs( "filteredBlobs.txt" );
//return blobs;
return blobs;
}
示例12: on_trackbar
// threshold trackbar callback
void on_trackbar( int dummy )
{
if(!originalThr)
{
originalThr = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,1);
}
if(!displayedImage)
{
displayedImage = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,3);
}
// threshold input image
cvThreshold( original, originalThr, param1, 255, CV_THRESH_BINARY );
// get blobs and filter them using its area
CBlobResult blobs;
int i;
CBlob *currentBlob;
// find blobs in image
blobs = CBlobResult( originalThr, NULL, 255 );
blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );
// display filtered blobs
cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );
for (i = 0; i < blobs.GetNumBlobs(); i++ )
{
currentBlob = blobs.GetBlob(i);
currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
}
cvShowImage( wndname, displayedImage );
}
示例13: while
/**
- FUNCTION: CBlobResult
- FUNCTIONALITY: Copy constructor
- PARAMETERS:
- source: object to copy
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borr�s
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
CBlobResult::CBlobResult( const CBlobResult &source )
{
// creem el nou a partir del passat com a par�metre
//m_blobs = Blob_vector( source.GetNumBlobs() );
m_blobs.reserve(source.GetNumBlobs());
// copiem els blobs de l'origen a l'actual
Blob_vector::const_iterator pBlobsSrc = source.m_blobs.begin();
Blob_vector::iterator pBlobsDst = m_blobs.begin();
while( pBlobsSrc != source.m_blobs.end() )
{
// no podem cridar a l'operador = ja que Blob_vector �s un
// vector de CBlob*. Per tant, creem un blob nou a partir del
// blob original
m_blobs.push_back(new CBlob(**pBlobsSrc));
pBlobsSrc++;
}
}
示例14: extractBall
void extractBall()
{
imgTransform(BALL_HUE_U, BALL_HUE_L, BALL_SAT_U, BALL_SAT_L, VAL_U, VAL_L);
blobRes = CBlobResult(dst, NULL, 0);
blobRes.Filter( blobRes, B_EXCLUDE, CBlobGetArea(), B_LESS, BLOB_SIZE_MIN );// keep blobs larger than BLOB_SIZE_MIN
numOfBlobs = blobRes.GetNumBlobs(); cout << numOfBlobs << endl;
blobRes.Filter( blobRes, B_EXCLUDE, CBlobGetArea(), B_GREATER, BALL_SIZE_MAX );// keep blobs smaller than BALL_SIZE_MAX
numOfBlobs = blobRes.GetNumBlobs(); cout << numOfBlobs << endl;
blobRes.Filter( blobRes, B_INCLUDE, CBlobGetCompactness(), B_GREATER, BALL_COMPACTNESS );// keep blobs greater than BALL_COMPACTNESS
numOfBlobs = blobRes.GetNumBlobs(); cout << numOfBlobs << endl;
for(int i=0; i<numOfBlobs; i++)
blobs[i] = blobRes.GetBlob(i);
};
示例15: extractBlob
coord extractBlob(CBlobResult blobs, coord selectedCoord){
coord coordinate;
CBlob Blob;
if ( blobs.GetNumBlobs()==0 ) {
coordinate.flag=false;
return coordinate;
}
else {
//!Get the blob info
Blob = getNearestBlob( blobs, selectedCoord);
//!Creating the coordinate struct
coordinate.set( (int) Blob.MaxX(), (int) Blob.MinX(), (int) Blob.MaxY(), (int) Blob.MinY());
return coordinate;
}
}