Identifiers switch undefined / defined with not changes on code!

asked 2019-10-20 17:30:44 -0600

fabianc20 gravatar image

updated 2019-10-22 07:22:31 -0600

supra56 gravatar image

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);
}
edit retag flag offensive close merge delete

Comments

I am following Opencv by example exercise 6

can you give us a link ?

include "openc2/MultipleImageWindow.h"

that's not from the opencv src code

suddently throwing E0020 error code

we cannot see any error msgs in your question, please add those.

berak gravatar imageberak ( 2019-10-21 00:25:56 -0600 )edit
1

@berak. Here is link; Example 6

supra56 gravatar imagesupra56 ( 2019-10-21 23:22:50 -0600 )edit