You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OpenCV+OpenVINO运行神经网络遇LNK2001未解析外部符号错误

链接器错误LNK2001:未解析外部符号__imp_PathIsRelativeA(OpenCV+OpenVINO)

我从源码编译OpenVINO后再编译OpenCV,在Visual Studio 2022中运行以下代码时遇到LNK2001错误,提示未解析外部符号__imp_PathIsRelativeA。开发环境运行库设置为Multi-threaded DLL (/MD),已添加OpenCV所需的所有库。

实现代码

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;
}

解决方案

  • 打开Visual Studio项目属性,依次进入链接器 -> 输入 -> 附加依赖项,添加shlwapi.lib后保存设置。

原因说明

PathIsRelativeA是Windows Shell API中的函数,属于shlwapi.lib库。OpenVINO或OpenCV的相关模块在编译时依赖该函数,但未自动完成链接,因此需要手动将该库添加到项目依赖中。

内容的提问来源于stack exchange,提问作者tridjam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 08:15:02