英文:
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 = "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;
}
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
添加到项目属性中的链接器输入后解决: "配置属性 > 链接器 > 输入 > 附加依赖项"
或通过以下预处理指令:
#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"
or by the following pragma:
#pragma comment(lib, "Shlwapi.lib")
Read more: https://stackoverflow.com/questions/38167618/how-can-i-use-the-c-shlwapi-library-in-visual-studio
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论