1

I am trying use yolov3 model to predict using opencv dnn module. It works perfectly in python but when I run in c++ (same configurations), it doesn't predict as the python code does. Neither there is an error. The output is plain, no predictions. The cpp code is as below. I got the reference from: text

int main(){

    string classesFile = Path;
    ifstream ifs(classesFile.c_str());
    string line;
    while (getline(ifs, line)) classes.push_back(line);

    // load model weights and architecture
    String configuration = Path;
    String model = Path;

    // Load the network
    Net net = readNetFromDarknet(configuration, model);
    Mat frame, blob;

    // read the image
    frame = cv::imread("image.jpg");

    // convert image to blob
    blobFromImage(frame, blob, 1 / 255 , cvSize(width, height), true, false);
    cout << endl << blob.size << endl << endl;


    net.setInput(blob);
    net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
    net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
    vector<Mat> outs;

    net.forward(outs, getOutputsNames(net));
    
    // postprocess to draw the predictions
    postprocess(Mat& frame, const std::vector<Mat>& outs, Net& net, int backend);

    }

The blob size seems to be correct. Not sure of the data that the blob is having. Tried changing opencv version but in vain. Doubtful about the blob. opencv veresion - 3.6.0

0 Answers0