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 4615364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:49:46+00:00 2026-05-22T01:49:46+00:00

I’m somewhat new to OpenCV and for some reason, I’m not managing to get

  • 0

I’m somewhat new to OpenCV and for some reason, I’m not managing to get CamShift to work in C++. First of all, if anyone has a working CamShift example using the C++ interface I would really appreciate it.

Second, I’m trying to adapt the C example to C++, just to get it to work. Nothing fancy, yet. Basically, what I’m doing is this:

// -----------------------

cv::Rect rect = /* some rectangle */;
cv::Mat img = /* some image */;

int bins = 16;
int sMin = 10;
int vMin = 10;
int vMax = 250;

cv::MatND hist(1, &bins, CV_8UC1);

cv::Rect searchWindow = rect;
cv::Mat roi = img(searchWindow);
cv::Mat hsv;
cv::cvtColor(roi, hsv, CV_RGB2HSV);

cv::Mat mask;
cv::inRange(hsv, cv::Scalar(0, sMin, vMin, 0), cv::Scalar(181, 256, vMax, 0), mask);

const int channel = 0;
float range[] = {0, 181};
const float* ranges[] = {range};
cv::calcHist(&hsv, 1, &channel, mask, hist, 1, &bins, ranges, true, false);

double histMax;
cv::minMaxLoc(hist, NULL, &histMax);

hist *= histMax ? 255.0 / histMax : 0.0;

int channel = 0;
float range[] = {0, 256};
const float* ranges[] = {range};
cv::Mat bp;
cv::calcBackProject(&img, 1, &channel, hist, bp, ranges, 1, true);

cv::RotatedRect foundObject = cv::CamShift(bp, searchWindow,
   cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 10, 1));

// -----------------------
// -----------------------
// -----------------------
// -----------------------

After this, what happens is that inside cv::CamShift(), despite the parameters having seemingly valid values, OpenCV throws a cv::Exception and crashes with the following message:

OpenCV Error: Assertion failed (box.size.width >= 0 && box.size.height >= 0 && t
hickness <= 255) in unknown function, file ..\..\..\..\ocv\opencv\src\cxcore\cxd
rawing.cpp, line 1666

There doesn’t seem to be any related bug on the bug tracking database, so… what am I missing something, here?

  • 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-22T01:49:46+00:00Added an answer on May 22, 2026 at 1:49 am

    It is a moderately easy-to-replicate bug. There are situations that arise (moving too fast, especially bumping the camera) that cause the logic of cv::RotatedRect( … ) to explode and create a box that either collapses to a point or is bigger than the frame. This error is then caught.

    When doing exactly this I just made a copy of the code and manually check the box-size in offending places. But at the end of the day I would say this function assumes that your camera is fixed and the scene lighting doesn’t change much. It won’t work mounted on a car driving around trying to track other cars, for example.

    Crashes like this are a great example of why “unit testing” and “code practices” break down in computer vision; its not enough to check that it runs on the test server with no display, but it also needs to run for all ranges of parameters, data spectrum, and user behaviors…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace

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.