Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6382577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:32:25+00:00 2026-05-25T02:32:25+00:00

I am trying to detect objects with cvblob. Somehow, my code only marks the

  • 0

I am trying to detect objects with cvblob. Somehow, my code only marks the white objects. How to mark objects of other colors, like a can of beer or a bottle of water.

Here is my code:

#include "highgui.h"
#include "cv.h"
#include "cvaux.h"
#include "iostream"
#include <stdio.h>
#include <ctype.h>

#include <cvblob.h>

using namespace cv;
using namespace std;
using namespace cvb;

int main(int argc, char** argv) {
    CvTracks tracks;

    cvNamedWindow("frame", CV_WINDOW_AUTOSIZE);
    cvMoveWindow("frame", 50, 100);

    CvCapture* capture;

    IplImage* frame = 0;

    capture = cvCreateCameraCapture( 0 ); //capture frames from cam on index 0: /dev/video0/

    if (!capture) {
        return -1;
    }

    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);

    frame = cvQueryFrame(capture);

    while(frame) {
        IplImage *gray = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
        cvCvtColor(frame, gray, CV_BGR2GRAY);
        cvThreshold(gray, gray, 150, 255, CV_THRESH_BINARY);

        IplImage *labelImg=cvCreateImage(cvGetSize(gray), IPL_DEPTH_LABEL, 1);
        CvBlobs blobs;
        unsigned int result=cvLabel(gray, labelImg, blobs);

        cvFilterByArea(blobs, 500, 1000000);
//        cvRenderBlobs(labelImg, blobs, frame, frame, CV_BLOB_RENDER_BOUNDING_BOX);
        cvRenderBlobs(labelImg, blobs, frame, frame, CV_BLOB_RENDER_CENTROID);
        cvUpdateTracks(blobs, tracks, 200., 5);
        cvRenderTracks(tracks, frame, frame, CV_TRACK_RENDER_ID|CV_TRACK_RENDER_BOUNDING_BOX);


        for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it) {
            cout << "Blob #" << it->second->label << ": Area=" << it->second->area << ", Centroid=(" << it->second->centroid.x << ", " << it->second->centroid.y << ")" << endl;
        }

        cvShowImage("frame", frame);

        cout << "----------------------------" << endl;

        frame = cvQueryFrame(capture);

        char c = cvWaitKey(10);
        if(c==27)
            break;

    }
}

Any tip is appreciated.

Milo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:32:26+00:00Added an answer on May 25, 2026 at 2:32 am

    That’s the option by default and you cannot change it if you don’t change the source code in cvblob library.

    If you really want to change this is so easy, you can create a copy of the same method adding a new input var like CvScalar to select output color. It’s so easy.

    The method cvRenderBlob will be in cvcontour.cpp.

    I’ve been made many improvement in cvblob library and in next months I will push it to the creator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to detect the compiler used to compile my source code. I can
I am trying to detect the collision from two objects. This collision has more
I am trying to detect various objects containing colored markers, so a red blue
I have two circular objects. I'm trying to detect as soon as the circles
I am trying to detect objects in image on an iphone app. I am
I am trying to detect the browser in my C# code by comparing the
I'm trying to detect the size of the screen I'm starting emacs on, and
I am trying to detect which web in sharepoint that the user is looking
I'm trying to detect when the onresize event ends in a browser. If I
I'm trying to detect Use after free() bugs, otherwise known as Dangling pointers. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.