Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Identifiers switch undefined / defined with not changes on code!

identifiers switch from being properly recognized to suddently throwing E0020 error code "Identifier ... is undefined". I change nothing in the code. I have learned that just adding or deleting blank lines makes the red underlines go away -and so do the warning and error flags- then I can rebuild the project with not errors.

It is wierd because I have done not changes to any single line of code to get back to 'normal'. Sometimes just waiting and saving the project does get rid of the undefined flags.

I am following Opencv by example exercise 6, as follows: Be aware that I have move libraries to the standard c:/opencv location I have been able to make all the previous 5 exercises just fine.

// OpenCV by example - Chapter 6 Classification

include <iostream>

include <string>

include <sstream>

include <cmath>

using namespace std;

// OpenCV includes

include "opencv2/core.hpp"

include "opencv2/imgproc.hpp"

include "opencv2/imgcodecs.hpp"

include "opencv2/highgui.hpp"

include "opencv2/ml.hpp"

include "opencv2/MultipleImageWindow.h"

using namespace cv; using namespace cv::ml;

MultipleImageWindow* miw; Mat light_pattern; Ptr<svm> svm=SVM::create(); Scalar green(0, 255, 0), blue(255, 0, 0), red(0, 0, 255);

// OpenCV command line parser functions // Keys accecpted by command line parser const char* keys = { "{help h usage ? | | print this message}" "{@image |test.pgm| Image to classify}" };

static Scalar randomColor(RNG& rng) { int icolor = (unsigned)rng; return Scalar(icolor & 255, (icolor >> 8) & 255, (icolor >> 16) & 255); }

void plotTrainData(Mat trainData, Mat labels, float* error = NULL) { float area_max, ar_max, area_min, ar_min; area_max = ar_max = 0; area_min = ar_min = 99999999; // Get the min and max of each feature for normalize plot image for (int i = 0; i < trainData.rows; i++) { float area = trainData.at<float>(i, 0); float ar = trainData.at<float>(i, 1); if (area > area_max) area_max = area; if (ar > ar_max) ar_max = ar; if (area < area_min) area_min = area; if (ar < ar_min) ar_min = ar; }

// Create Image for plot
Mat plot = Mat::zeros(512, 512, CV_8UC3);   // HERE THE CV_8UC3 IDENTIFIER ONE OF THOSE THAT MISSBEHAIVES 

// Plot each of two features in a 2D graph using an image
// where x is area and y is aspect ratio
for (int i = 0; i < trainData.rows; i++) {
    // Set the X y pos for each data
    float area = trainData.at<float>(i, 0);
    float ar = trainData.at<float>(i, 1);
    int x = (int)(512.0f * ((area - area_min) / (area_max - area_min)));
    int y = (int)(512.0f * ((ar - ar_min) / (ar_max - ar_min)));

    // Get label
    int label = labels.at<int>(i);
    // Set color depend of label
    Scalar color;
    if (label == 0)
        color = green; // NUT
    else if (label == 1)
        color = blue; // RING
    else if (label == 2)
        color = red; // SCREW

    circle(plot, Point(x, y), 3, color, -1, 8);
}

if (error != NULL) {
    stringstream ss;
    ss << "Error: " << *error << "\n";
    putText(plot, ss.str().c_str(), Point(20, 512 - 40), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(200, 200, 200), 1, LINE_AA);
}
miw->addImage("Plot", plot);

}

Identifiers switch undefined / defined with not changes on code!

identifiers switch from being properly recognized to suddently throwing E0020 error code "Identifier ... is undefined". I change nothing in the code. I have learned that just adding or deleting blank lines makes the red underlines go away -and so do the warning and error flags- then I can rebuild the project with not errors.

It is wierd because I have done not changes to any single line of code to get back to 'normal'. Sometimes just waiting and saving the project does get rid of the undefined flags.

I am following Opencv by example exercise 6, as follows: Be aware that I have move libraries to the standard c:/opencv location I have been able to make all the previous 5 exercises just fine.

// OpenCV by example - Chapter 6 Classification

include <iostream>

include <string>

include <sstream>

include <cmath>

Classification #include <iostream> #include <string> #include <sstream> #include <cmath> using namespace std;

std; // OpenCV includes

include "opencv2/core.hpp"

include "opencv2/imgproc.hpp"

include "opencv2/imgcodecs.hpp"

include "opencv2/highgui.hpp"

include "opencv2/ml.hpp"

include "opencv2/MultipleImageWindow.h"

includes #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/ml.hpp" #include "opencv2/MultipleImageWindow.h" using namespace cv; using namespace cv::ml;

cv::ml; MultipleImageWindow* miw; Mat light_pattern; Ptr<svm> Ptr<SVM> svm=SVM::create(); Scalar green(0, 255, 0), blue(255, 0, 0), red(0, 0, 255);

255); // OpenCV command line parser functions // Keys accecpted by command line parser const char* keys = { "{help h usage ? | | print this message}" "{@image |test.pgm| Image to classify}" };

}; static Scalar randomColor(RNG& rng) { int icolor = (unsigned)rng; return Scalar(icolor & 255, (icolor >> 8) & 255, (icolor >> 16) & 255); }

} void plotTrainData(Mat trainData, Mat labels, float* error = NULL) { float area_max, ar_max, area_min, ar_min; area_max = ar_max = 0; area_min = ar_min = 99999999; // Get the min and max of each feature for normalize plot image for (int i = 0; i < trainData.rows; i++) { float area = trainData.at<float>(i, 0); float ar = trainData.at<float>(i, 1); if (area > area_max) area_max = area; if (ar > ar_max) ar_max = ar; if (area < area_min) area_min = area; if (ar < ar_min) ar_min = ar; }

}

    // Create Image for plot
 Mat plot = Mat::zeros(512, 512, CV_8UC3);   // HERE THE CV_8UC3 IDENTIFIER ONE OF THOSE THAT MISSBEHAIVES 

 // Plot each of two features in a 2D graph using an image
 // where x is area and y is aspect ratio
 for (int i = 0; i < trainData.rows; i++) {
     // Set the X y pos for each data
     float area = trainData.at<float>(i, 0);
     float ar = trainData.at<float>(i, 1);
     int x = (int)(512.0f * ((area - area_min) / (area_max - area_min)));
     int y = (int)(512.0f * ((ar - ar_min) / (ar_max - ar_min)));

     // Get label
     int label = labels.at<int>(i);
     // Set color depend of label
     Scalar color;
     if (label == 0)
         color = green; // NUT
     else if (label == 1)
         color = blue; // RING
     else if (label == 2)
         color = red; // SCREW

     circle(plot, Point(x, y), 3, color, -1, 8);
 }

 if (error != NULL) {
     stringstream ss;
     ss << "Error: " << *error << "\n";
     putText(plot, ss.str().c_str(), Point(20, 512 - 40), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(200, 200, 200), 1, LINE_AA);
 }
 miw->addImage("Plot", plot);
}

}