OpenCV - 缺少 dll

Posted

技术标签:

【中文标题】OpenCV - 缺少 dll【英文标题】:OpenCV - missing dlls 【发布时间】:2017-08-09 11:54:28 【问题描述】:

使用 OpenCV 3.3.0

使用 Visual Studio 2017,我尝试运行我的代码,但没有发现任何错误。 总是说“应用程序无法正确启动(0xc000007b)”(翻译)。

debug 文件夹中已经有这个 dll 文件:

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

这是我的代码:

#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));
    

************** 更新 1 **************

Dependency Walker 的结果:

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

【问题讨论】:

不确定,但这看起来像 c++/cli,而不是 c++ 也许你错过了类似opencv_features2d330d.dll的东西。 @tobi303 没错!对不起 @DimChtz 我没有那个文件 那么您需要确定您还有哪些其他 dll 依赖项,可能是 ffmpeg 或哈希 dll 有一些其他 dll 依赖项。您可以使用dependencywalker.com 来查找此问题,将每个 dll 拖放到窗口中,记下 dll 要求,然后查看是否可以发现缺少的内容。 【参考方案1】:

我编译的库错了!

    从official website下载Cmake并安装; 转到OpenCV Repo; 下载最新版本并解压到一个文件夹中; 转到OpenCV-contrib Repo,下载最新版本并 也提取它; 打开Cmake-gui,将source code设置为opencv的文件夹; 将build the binaries设置为空文件夹,设置为configure; 搜索OPENCV_ENABLE_NONFREE并检查它,同时搜索 OPENCV_EXTRA_MODULES_PATH 并设置模块文件夹的路径 已提取的 opencv-contrib 内部; 再次点击configure,然后点击generate,最后点击open project; 只需点击编译,所有文件都会在那里。

【讨论】:

以上是关于OpenCV - 缺少 dll的主要内容,如果未能解决你的问题,请参考以下文章

缺少使用 viola opencv core2410d.dll 的 Opencv 人脸检测

程序无法启动,因为缺少 opencv_core2410d.dll

OpenCV 程序无法启动,因为 Visual Studio 2010 中缺少 MSVCP110D.dll

由于在 Code::Block 中缺少“libgcc_s_dw2-1.dll”,OpenCV 程序无法运行

“程序无法启动,因为您的计算机中缺少 opencv_world300.dll”C++ 中的错误

VS2013 + Win7 中缺少 MSVCP140.dll