Unresolved externals when creating a mex function

8 次查看(过去 30 天)
I am creating a simple mex function for the OpenCV imread() function. This will allow me to read freames from a camera stream.
I receive an error stating that I have two, unresolved externals as shown below:
error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const &,int)"
I am able to use the imread() functionality directly from Visual Studio in my Python and C++ scripts so there is no problem with my OpenCV download. In the code that I have pasted below, all functionallity with the cv::createBackgroundSubtractorMOG2() works perfectly. ie: when I compile the mex function with only that functionallity, it works fine.
Why is it that functionallity with the cv::createBackgroundSubtractorMOG2() works fine but when I add in the imread() function it gives me the errors.
This is my code:
#include "opencvmex.hpp"
using namespace cv;
static Ptr<BackgroundSubtractorMOG2> ptrBackgroundModel = cv::createBackgroundSubtractorMOG2();
// Static smart pointer to hold the loaded image
static Ptr<Mat> ptrImage = makePtr<Mat>();
// Function to load an image from a file
void loadImageFromFile(const std::string& filename) {
// Load the image from file
Mat image = cv::imread(filename);
// Assign the loaded image to the static smart pointer
*ptrImage = image;
}
  2 个评论
James Tursa
James Tursa 2024-5-3
编辑:James Tursa 2024-5-3
Why is the error message showing a imread() signature with four arguments but your example code imread() has only one argument? Are there other imread() calls in your code that have four arguments?
Are there multiple libraries you need to link with?
Doron Joffe
Doron Joffe 2024-5-10
I managed to resolve the problem. The issue was that I was not linking the opencv lib file in the mex call. When compiling my mex file, the call needed to be mexOpenCV loadImage.cpp -lopencv_world460.lib

请先登录,再进行评论。

回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by