Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

why may detectMultiScale() give too many points out of the interested object?

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

image description

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

image description

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

Here's my code:

include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  //equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, 0, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}

I have also tried to reduce the number of neighbours but the effect is the same, just with many less points...

why may detectMultiScale() give too many points out of the interested object?

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

image description

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

image description

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

Here's my code:

include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  //equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, 0, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}

I have also tried to reduce the number of neighbours but the effect is the same, just with many less points...points... Could it be a problem the fact that in positive images there are those 4 corners as background around the coin? I generated png images with Gimp from a shot video showing the coin, so I don't know why opencv_createsamples puts those 4 corners.

why may detectMultiScale() give too many points out of the interested object?

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

image description

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

image description

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

Here's my code:

include "opencv2/opencv.hpp"

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  //equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, 0, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}

I have also tried to reduce the number of neighbours but the effect is the same, just with many less points... Could it be a problem the fact that in positive images there are those 4 corners as background around the coin? I generated png images with Gimp from a shot video showing the coin, so I don't know why opencv_createsamples puts those 4 corners.

why may detectMultiScale() give too many points out of the interested object?

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

image description

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

image description

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

Here's my code:

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  //equalizeHist(src_gray, equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, 0, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}

I have also tried to reduce the number of neighbours but the effect is the same, just with many less points... Could it be a problem the fact that in positive images there are those 4 corners as background around the coin? I generated png images with Gimp from a shot video showing the coin, so I don't know why opencv_createsamples puts those 4 corners.

UPDATE I also tried to create a LBP cascade.xml but this is quite strange: in fact, if I use, in the abve OpenCV program, an image used as training, then the detection is good: image description

Instead, if I use another image (for example, taken by my smartphone) there there's nothing detected. What does it mean this? Have I made any error during training?

why may detectMultiScale() give too many points out of the interested object?

I trained my pc with opencv_traincascade all one day long to detect 2€ coins using more than 6000 positive images similar to the following:

image description

Now, I have just tried to run a simple OpenCV program to see the results and to check the file cascade.xml. The final result is very disappointing:

image description

There are many points on the coin but there are also many other points on the background. Could it be a problem with my positive images used for training? Or maybe, am I using the detectMultiScale() with wrong parameters?

Here's my code:

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int, char**) {

  Mat src = imread("2c.jpg", CV_LOAD_IMAGE_COLOR); 

  Mat src_gray;

  std::vector<cv::Rect> money;

  CascadeClassifier euro2_cascade;

  cvtColor(src, src_gray, CV_BGR2GRAY );
  equalizeHist(src_gray, src_gray);

  if ( !euro2_cascade.load( "/Users/lory/Desktop/cascade.xml" ) ) {
     printf("--(!)Error loading\n");
     return -1;
  }

  euro2_cascade.detectMultiScale( src_gray, money, 1.1, 0, 0, cv::Size(10, 10),cv::Size(2000, 2000) );

  for( size_t i = 0; i < money.size(); i++ ) {
     cv::Point center( money[i].x + money[i].width*0.5, money[i].y + money[i].height*0.5 );
     ellipse( src, center, cv::Size( money[i].width*0.5, money[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
  }

  //namedWindow( "Display window", WINDOW_AUTOSIZE );
  imwrite("result.jpg",src);
}

I have also tried to reduce the number of neighbours but the effect is the same, just with many less points... Could it be a problem the fact that in positive images there are those 4 corners as background around the coin? I generated png images with Gimp from a shot video showing the coin, so I don't know why opencv_createsamples puts those 4 corners.

UPDATE I also tried to create a LBP cascade.xml but this is quite strange: in fact, if I use, in the abve OpenCV program, an image used as training, then the detection is good: image description

Instead, if I use another image (for example, taken by my smartphone) there there's nothing detected. What does it mean this? Have I made any error during training?

image description