Bundled C++ Code that uses opencv into a .dll - issues

Hi all,

I bundled code into a .dll that uses opencv, when I run the function from the .dll - it works correctly including opencv functions except for one issue.

Imread returns a nullptr when it tries to load an image.

When I take the code out of the .dll and create a console application that uses it, imread works perfectly. It is not a file path issue, and I want to reiterate that other opencv functiosn work in the .dll.

Thanks

it does NOT return a pointer in the 1st place. (but an empty Mat on failure)

can you please show, what you are doing here ?

image

thanks for the info, but please NEVER post IMAGES of code or errors anywhere, but TEXT , (how do yo expect ppl to try, what you do ?), thank you.

Sorry, first post. Will try again.

1 Like
#include "pch.h"
#include "framework.h"
#include "scratchdll.h"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <vector>
#include <string>
#include <iostream>
#include <experimental/filesystem>

using namespace cv;
using std::experimental::filesystem::exists;

extern "C"
{
    _declspec(dllexport) void imshowgui() {
        String title = "C://Users//remove//Desktop//gc.png";
        std::cout << exists(title);
        std::cout << "\n" << title << "\n";
        Mat img = imread(title,IMREAD_UNCHANGED);
        
        std::cout << "\n" << img.rows << "," << img.cols << "\n";
        int c = waitKey(0);
        int i = 1;
        namedWindow("img", WINDOW_AUTOSIZE);
        while (i == 1) {
            imshow("img", img);
            c = waitKey(0);
            std::cout << waitKey << "\n";
            if (c == 99) {
                i = 0;
            }
        }
        std::cout << "Hello World!\n";
    }
}

well, that should work…

  • do yo see the expected console output ?

  • do you see the GUI window ?

  • can you attach the image (is it really a png ?) ?

  • note, that waitKey(0) will wait forever,
    and that the GUI window needs to have focus here !

Hi berak,

Sorry for the late reply. The code creates a GUI window and attempts to load the PNG. The issue is that it returns an empty Mat.

Thanks