Why is the simple blob detector SO SLOOOW?

asked 2017-12-18 06:31:14 -0500

As you can see in the tile our simple blob detection programm is very slow.

When we delete the detect(cameraFrame, keypoints1c); command, it is much more smoothly.

Is it just normal or do we something wrong?

#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

//Anlegen der Variablen
int minA1c = 1000;
int maxA1c = 11000;
int minA2c = 11000;
int maxA2c = 15000;
int minA5c = 15000;
int maxA5c = 50000;
int minT = 100;
int maxT = 1000;



int main(int argc, char** argv)
{

//Starten der Kamera, Wert in Klammern = ID der Kamera
VideoCapture stream(0);

cout << "Properties: width=" << stream.get(CAP_PROP_FRAME_WIDTH);
cout << "px, height=" << stream.get(CAP_PROP_FRAME_HEIGHT);


// Fehlermeldung wenn nicht auf Kamera zugegriffen werden kann
if (!stream.isOpened())
{
    cout << "Kann die Kamera nicht öffnen";
}

// Setup SimpleBlobDetector parameters.

SimpleBlobDetector::Params params1c;
SimpleBlobDetector::Params params2c;
SimpleBlobDetector::Params params5c;

// Change thresholds
//Je dunkler desto niedriger der threshold
params1c.minThreshold = minT;
params1c.maxThreshold = maxT;
params2c.minThreshold = minT;
params2c.maxThreshold = maxT;
params5c.minThreshold = minT;
params5c.maxThreshold = maxT;

// Filter by Area.
params1c.filterByArea = true;
params1c.minArea = minA1c;
params1c.maxArea = maxA1c;
params2c.filterByArea = true;
params2c.minArea = minA2c;
params2c.maxArea = maxA2c;
params5c.filterByArea = true;
params5c.minArea = minA5c;
params5c.maxArea = maxA5c;

// Storage for blobs
vector<KeyPoint> keypoints1c;
vector<KeyPoint> keypoints2c;
vector<KeyPoint> keypoints5c;

// Set up detector with params
Ptr<SimpleBlobDetector> detector1c = SimpleBlobDetector::create(params1c);
Ptr<SimpleBlobDetector> detector2c = SimpleBlobDetector::create(params2c);
Ptr<SimpleBlobDetector> detector5c = SimpleBlobDetector::create(params5c);

//Erstellen der Fenster mit Positionen
cvNamedWindow("Kamera Blobs", WINDOW_AUTOSIZE);
cvMoveWindow("Kamera Blobs", 350, 200);


while (true)
{
    //Anlegen der Matritzen für die Frames
    Mat cameraFrame;
//  Mat cameraBlobs;

    //Auslesen der Kameraframes
    stream.read(cameraFrame);

    //Umwandeln in Graubild
//  cvtColor(cameraFrame, cameraFramegrey, COLOR_BGR2GRAY);

    //Erkennen der Blobs
    detector1c->detect(cameraFrame, keypoints1c);
//  detector2c->detect(cameraFrame, keypoints2c);
//  detector5c->detect(cameraFrame, keypoints5c);

    //Zeichnen der Blobs
    drawKeypoints(cameraFrame, keypoints1c, cameraFrame, Scalar(0, 255, 0), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);     
    drawKeypoints(cameraFrame, keypoints2c, cameraFrame, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
    drawKeypoints(cameraFrame, keypoints5c, cameraFrame, Scalar(255, 0, 0), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

    //Anzahl der Blobs
    size_t a = keypoints1c.size();
    size_t b = keypoints2c.size();
    size_t c = keypoints5c.size();

    //Textausgabe in Bild
    std::string anza = std::to_string(a);
    std::string anzb = std::to_string(b);
    std::string anzc = std::to_string(c);


    string labela = "1 cent Muenzen: " + anza;
    string labelb = "2 cent Muenzen: " + anzb;
    string labelc = "5 cent Muenzen: " + anzc;


    putText(cameraFrame, labela, Point(50, 50), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 0, 0), 2.0); //1 cent
    putText(cameraFrame, labelb, Point(50, 100), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 0, 0), 2.0);//2 cent
    putText(cameraFrame, labelc, Point(50, 150), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0, 0, 0), 2.0);//5 cent


    //Aufaddieren der Werte
//  int wert = a;
    //cout <<"Wert: ";
    //cout << a;

    //Anzeigen der Frames im Fenster
    imshow("Kamera Blobs", cameraFrame);




    //Schließen bei Klick auf Taste mit der ID 27 keycode.info
    if (waitKey(30) == 27)
        break;
}
return 0;
  }

Our system: 64-Bit Windows 7

64 Gb RAM

12 core Intel Xeon CPU E5-1650 v3 @3.5 GHz

Visual Studio 2017

edit retag flag offensive close merge delete

Comments

"As you can see in the tile our simple blob detection programm is very slow. " where? Are you in debug or release?

LBerger gravatar imageLBerger ( 2017-12-18 06:43:49 -0500 )edit

I am in debug

frodobeutlin gravatar imagefrodobeutlin ( 2017-12-18 06:54:32 -0500 )edit

try in release and come back to write :

1 in debug and in release it is very slow

or

2 in release that's not very slow

LBerger gravatar imageLBerger ( 2017-12-18 07:08:41 -0500 )edit