LNK2001 未解析的外部符号 __imp_PathIsRelativeA

huangapple go评论62阅读模式
英文:

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, 0.007843f, Size(300, 300), Scalar(127.5f, 127.5f, 127.5f), false);

    // 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;
}
英文:

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 = &quot;C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.mapping&quot;;
string xml_path = &quot;C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.xml&quot;;
string bin_path = &quot;C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.bin&quot;;
// 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(&quot;C:\\ROOT1\\opencv_build_test\\car_300x300.jpg&quot;);
// 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 &lt; detections_reshaped.rows; ++i) {
float confidence = detections_reshaped.at&lt;float&gt;(i, 2);
if (confidence &gt; 0.5) {
int x_left = static_cast&lt;int&gt;(detections_reshaped.at&lt;float&gt;(i, 3) * img.cols);
int y_top = static_cast&lt;int&gt;(detections_reshaped.at&lt;float&gt;(i, 4) * img.rows);
int x_right = static_cast&lt;int&gt;(detections_reshaped.at&lt;float&gt;(i, 5) * img.cols);
int y_bottom = static_cast&lt;int&gt;(detections_reshaped.at&lt;float&gt;(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(&quot;Image&quot;, img);
waitKey();
}
int main()
{
TestOpenVinoModel();
return 0;
}

LNK2001 未解析的外部符号 __imp_PathIsRelativeA

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).

答案1

得分: 2

PathIsRelativeA 是来自 Shlwapi.dll 的 Windows API 函数。
问题应该在将 Shlwapi.lib 添加到项目属性中的链接器输入后解决: "配置属性 > 链接器 > 输入 > 附加依赖项"
LNK2001 未解析的外部符号 __imp_PathIsRelativeA

或通过以下预处理指令:

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

阅读更多: https://stackoverflow.com/questions/38167618/how-can-i-use-the-c-shlwapi-library-in-visual-studio

英文:

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"
LNK2001 未解析的外部符号 __imp_PathIsRelativeA

or by the following pragma:

#pragma comment(lib, &quot;Shlwapi.lib&quot;)

Read more: https://stackoverflow.com/questions/38167618/how-can-i-use-the-c-shlwapi-library-in-visual-studio

huangapple
  • 本文由 发表于 2023年3月7日 19:39:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75661504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定