0

I try to run a neural network using OpenCV with OpenVino but face an error LNK2001 unresolved external symbol __imp_PathIsRelativeA

void TestOpenVinoModel()
{    
    // Model
    string mapping_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.mapping";
    string xml_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.xml";
    string bin_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.bin";

    // Load the OpenVINO plugin for OpenCV
    Net openvino_model = readNetFromModelOptimizer(xml_path, bin_path);
    
    // Set target device to CPU
    openvino_model.setPreferableTarget(DNN_TARGET_CPU);

    // Load an image
    Mat img = imread("C:\\ROOT1\\opencv_build_test\\car_300x300.jpg");

    // Preprocess the image
    //Mat blob = blobFromImage(img, 1.0, Size(), Scalar(), true, false);
    Mat blob = blobFromImage(img, 0.007843f, Size(300, 300), Scalar(127.5f, 127.5f, 127.5f), false);
    //Mat blob;
    //cvtColor(img, blob, COLOR_BGR2RGB);
    //blob = blob.reshape(1, { 1, 3, 300, 300 });

    // Set input data for the network
    openvino_model.setInput(blob);

    // Run forward pass to get the output
    Mat detections = openvino_model.forward();

    // Post-process the output to extract the bounding boxes
    Mat detections_reshaped = detections.reshape(1, detections.total() / 7);

    // Draw bounding boxes on the original image
    for (int i = 0; i < detections_reshaped.rows; ++i) {
        float confidence = detections_reshaped.at<float>(i, 2);
        if (confidence > 0.5) {
            int x_left = static_cast<int>(detections_reshaped.at<float>(i, 3) * img.cols);
            int y_top = static_cast<int>(detections_reshaped.at<float>(i, 4) * img.rows);
            int x_right = static_cast<int>(detections_reshaped.at<float>(i, 5) * img.cols);
            int y_bottom = static_cast<int>(detections_reshaped.at<float>(i, 6) * img.rows);

            rectangle(img, Point(x_left, y_top), Point(x_right, y_bottom), Scalar(0, 0, 255), 2);
        }
    }

    // Display the resulting image
    imshow("Image", img);
    waitKey();
}

int main()
{
    TestOpenVinoModel();

    return 0;
}

enter image description here

I built OpenVino from sources and then built OpenCV. I added all libs that OpenCV needed. I develop the program in Visual Studio 2022 with Runtime library Multi-threaded DLL (/MD).

tridjam
  • 21
  • 2

1 Answers1

1

PathIsRelativeA is a Windows API function from Shlwapi.dll.
The problem should be solved after adding Shlwapi.lib to the linker inputs in the project properties: "Configuration Properties > Linker > Input > Additional Dependencies"
enter image description here

or by the following pragma:

#pragma comment(lib, "Shlwapi.lib")

Read more: How can I use the C++ shlwapi library in Visual Studio?

eltio
  • 94
  • 1
  • 1
  • 5
  • I tried to download this library and add it to project, then I added properties into linker. But it didn't help. What I did incorrectly? – tridjam Mar 09 '23 at 08:12
  • You don't need to download this library. Just add the line `Shlwapi.lib` to Additional Dependencies and rebuild your project. – eltio Mar 09 '23 at 17:42
  • I did as you adviced but it didn't help. I think I should add this library to the project somehow. How can I do it without downloading it? – tridjam Mar 10 '23 at 04:38
  • 1
    @tridjam The library is shipped with windows, you don't need to (and can't) download it. One thing to note when adding linker dependencies is that you do so for *all* project configurations. – Ofek Shilon Mar 18 '23 at 04:51