OpenCV - missing dlls

1

Using OpenCV 3.3.0

Using Visual Studio 2017, I try to run my code with no errors found. Always say "The application cound not start correctly (0xc000007b)"(Translated).

Already have this dll files in debug folder:

  • opencv_contrib_world330d.dll
  • opencv_ffmpeg.dll
  • opencv_ffmpeg330.dll
  • opencv_ffmpeg330_64.dll
  • opencv_ffmpeg_64.dll
  • opencv_img_hash330d.dll
  • opencv_world330.dll
  • opencv_world330d.dll

Here is my code:

#pragma once
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\core\ocl.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include "opencv2\xfeatures2d.hpp"

using namespace cv;
using namespace cv::ocl;
using namespace cv::xfeatures2d;
using namespace std;

extern "C"
{
    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

namespace ObjDetect_v1 {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::Runtime::InteropServices;

    Bitmap^ ConvertMatToBitmap(Mat matToConvert);

    /// <summary>
    /// Summary for Main
    /// </summary>
    public ref class Main : public System::Windows::Forms::Form
    {
    public:
        Main(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Main()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::PictureBox^  pictureBox_Cam;
    private: System::Windows::Forms::Button^  button_Start;
    private: System::Windows::Forms::PictureBox^  pictureBoxHist;
    private: System::Windows::Forms::PictureBox^  pictureBoxObj;


    private: System::ComponentModel::IContainer^  components;


    protected:

    protected:

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>


#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->pictureBox_Cam = (gcnew System::Windows::Forms::PictureBox());
            this->button_Start = (gcnew System::Windows::Forms::Button());
            this->pictureBoxHist = (gcnew System::Windows::Forms::PictureBox());
            this->pictureBoxObj = (gcnew System::Windows::Forms::PictureBox());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Cam))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBoxHist))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBoxObj))->BeginInit();
            this->SuspendLayout();
            // 
            // pictureBox_Cam
            // 
            this->pictureBox_Cam->Location = System::Drawing::Point(12, 12);
            this->pictureBox_Cam->Name = L"pictureBox_Cam";
            this->pictureBox_Cam->Size = System::Drawing::Size(422, 288);
            this->pictureBox_Cam->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
            this->pictureBox_Cam->TabIndex = 0;
            this->pictureBox_Cam->TabStop = false;
            // 
            // button_Start
            // 
            this->button_Start->Location = System::Drawing::Point(359, 409);
            this->button_Start->Name = L"button_Start";
            this->button_Start->Size = System::Drawing::Size(75, 23);
            this->button_Start->TabIndex = 1;
            this->button_Start->Text = L"Start";
            this->button_Start->UseVisualStyleBackColor = true;
            this->button_Start->Click += gcnew System::EventHandler(this, &Main::button_Start_Click);
            // 
            // pictureBoxHist
            // 
            this->pictureBoxHist->Location = System::Drawing::Point(463, 12);
            this->pictureBoxHist->Name = L"pictureBoxHist";
            this->pictureBoxHist->Size = System::Drawing::Size(422, 288);
            this->pictureBoxHist->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
            this->pictureBoxHist->TabIndex = 2;
            this->pictureBoxHist->TabStop = false;
            // 
            // pictureBoxObj
            // 
            this->pictureBoxObj->Location = System::Drawing::Point(540, 324);
            this->pictureBoxObj->Name = L"pictureBoxObj";
            this->pictureBoxObj->Size = System::Drawing::Size(300, 163);
            this->pictureBoxObj->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
            this->pictureBoxObj->TabIndex = 3;
            this->pictureBoxObj->TabStop = false;
            // 
            // Main
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(900, 508);
            this->Controls->Add(this->pictureBoxObj);
            this->Controls->Add(this->pictureBoxHist);
            this->Controls->Add(this->button_Start);
            this->Controls->Add(this->pictureBox_Cam);
            this->Name = L"Main";
            this->Text = L"Main";
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Cam))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBoxHist))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBoxObj))->EndInit();
            this->ResumeLayout(false);

        }
#pragma endregion
    private: System::Void button_Start_Click(System::Object^  sender, System::EventArgs^  e)
    {
        cv::ocl::setUseOpenCL(true);
        if (!cv::ocl::haveOpenCL())
        {
            MessageBox::Show("OpenCL is not available...", "WARNING");
        }

        cv::ocl::Context context;
        if (!context.create(cv::ocl::Device::TYPE_GPU))
        {
            MessageBox::Show("Failed creating the context...", "WARNING");
        }
        for (int i = 0; i != context.ndevices(); i++)
        {
            cv::ocl::Device device = context.device(i);
            MessageBox::Show(gcnew System::String(device.name().c_str()), "WARNING");
        }

        cv::ocl::Device(context.device(0));

        // INIT
        VideoCapture videoCap;
        videoCap.open(0);

        Mat frame;
        Mat frame_gray;
        Mat ObjIM;
        Mat ObjDescript;
        Mat frameDescript;
        vector<KeyPoint> objKeys;
        vector<KeyPoint> frameKeys;
        FeatureDetector * detector = new SIFT();
        DescriptorExtractor * extractor = new SIFT();

        // OBJ TRATMENT
        OpenFileDialog ^ openFileDialog = gcnew OpenFileDialog();
        openFileDialog->Filter = "PNG file |*.png";
        openFileDialog->Title = "Select a File to decrypt";
        if (openFileDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK)
        {
            IntPtr ptrToNativeString = Marshal::StringToHGlobalAnsi(openFileDialog->FileName);
            ObjIM = imread(static_cast<char*>(ptrToNativeString.ToPointer()), IMREAD_GRAYSCALE);
        }
        detector->detect(ObjIM, objKeys);
        extractor->compute(ObjIM, objKeys, ObjDescript);
        pictureBoxObj->Image = ConvertMatToBitmap(ObjIM);


        // FRAME TRATMENT
        videoCap.read(frame);
        pictureBox_Cam->Image = ConvertMatToBitmap(frame);
        cvtColor(frame, frame_gray, CV_BGR2GRAY);
        equalizeHist(frame_gray, frame_gray);
        detector->detect(frame, frameKeys);
        extractor->compute(frame, frameKeys, frameDescript);

        // FLANN
        Mat Result;
        Mat Dist;
        int k = 2;
        flann::Index flannIndex(frameDescript, flann::LshIndexParams(12,20,2), cvflann::FLANN_DIST_HAMMING);
        flannIndex.knnSearch(ObjDescript, Result, Dist, k, flann::SearchParams());

        if (Dist.type() == CV_32F)
        {
            Mat tmp;
            Dist.convertTo(tmp, CV_32F);
            Dist = tmp;
        }

        float nndrRatio = 0.8;
        vector<Point2f> mpts_1;
        vector<Point2f> mpts_2;
        vector<int> indexes_1;
        vector<int> indexes_2;
        vector<uchar> outlier_mask;

        for (unsigned int i = 0; i < ObjDescript.rows; i++)
        {
            if (Result.at<int>(i, 0) >= 0 &&
                Result.at<int>(i, 1) >= 0 &&
                Dist.at<float>(i, 0) <= nndrRatio * Dist.at<float>(i, 1))
            {
                mpts_1.push_back(objKeys.at(i).pt);
                indexes_1.push_back(i);
                mpts_2.push_back(frameKeys.at(Result.at<int>(i, 0)).pt);
                indexes_2.push_back(Result.at<int>(i,0));
            }
        }

        int nbMatches = 8;
        Mat FrameObj;
        if (mpts_1.size() >= nbMatches)
        {
            FrameObj = findHomography(mpts_1, mpts_2, RANSAC, 1, outlier_mask);
            //Rect(FrameObj,);
        }


        pictureBoxHist->Image = ConvertMatToBitmap(FrameObj);
    }
};
    Bitmap^ ConvertMatToBitmap(Mat matToConvert) {
        return gcnew Bitmap(matToConvert.cols, matToConvert.rows, 4 * matToConvert.rows, System::Drawing::Imaging::PixelFormat::Format24bppRgb, IntPtr(matToConvert.data));
    }
}

************** Update 1 **************

Result from Dependency Walker:

https://mega.nz/#!Ohd10LwD!eFyyhngvuwXTW7fkejc8NJToyXLx0b_Kw5IO3ycbY1Q

.net
opencv
dll
c++-cli
asked on Stack Overflow Aug 9, 2017 by Samega 7Cattac • edited Aug 9, 2017 by Samega 7Cattac

1 Answer

0

I was compiling the lib wrong!

  1. Download Cmake from official website and install it;
  2. Go to OpenCV Repo;
  3. Download the latest release and extract to a folder;
  4. Go to OpenCV-contrib Repo, download the latest release and extract it too;
  5. Open Cmake-gui and set the source code to the folder of opencv;
  6. Set build the binaries to a empty folder and it configure;
  7. Search for OPENCV_ENABLE_NONFREE and check it, also search for OPENCV_EXTRA_MODULES_PATH and set the path to the modules folder inside of the opencv-contrib already extracted;
  8. Hit configure again, then generate and finally open project;
  9. Just hit to compile and all the files will be there.
answered on Stack Overflow Sep 8, 2018 by Samega 7Cattac

User contributions licensed under CC BY-SA 3.0