首页 > 解决方案 > c++ opencv Net type with wrong ram allocation?

问题描述

嗨,我现在正在努力解决有关 opencv 网络类型的问题,它就像私有网络和公共函数:net = cv::dnn::readNetFromONNX(model_path); 但是这种类型有一些问题,虽然没有在 app.h 中声明它,而只是在 makedll.cpp 中声明,但所有其他参数都出现了错误的随机符号和数字,这意味着分配了错误的 ram。在 makedll.cpp 中:

class _declspec(dllexport) ocr
{
private:
    //const string _model_path = "./1.onnx";
    int crop_mode = 1;
    int thresh_mode = 1;
    int bitwise_mode2 = 0;
    double blur1 = 3;
    Net net;

在使用 dll.cpp 时:

class _declspec(dllimport) ocr
{
//private:
      //Net net; if i don't redeclare this type, print all params goes wrong.
public:
      func1(net,img);

ocr 的任何函数都会因堆栈溢出错误而退出,即使是只有 imshow(picture) 的简单 func 仍然相同。这意味着应用程序现在无法摆脱 opencv,希望得到任何帮助,谢谢!

更多详情如下:

     #pragma once
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/opencv_world453.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/ippicvmt.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libprotobuf.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/ippiw.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libjpeg-turbo.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/ittnotify.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/ade.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/zlib.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libopenjp2.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libpng.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/quirc.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/IlmImf.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libtiff.lib" )
#pragma comment( lib,"D:/opencv32/install/x86/vc14/staticlib/libwebp.lib" )
#include <stdlib.h>  
#include <iostream>
#include <fstream>

#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/all_layers.hpp>

#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include<cmath>
#include<windows.h>
#include <string>
using std::string;
//define interface

using namespace std;
using namespace cv;
using namespace dnn;
class _declspec(dllexport) ocr
{
private:
    //string _model_path;
    int crop_mode = 1;
    int thresh_mode = 1;
    int bitwise_mode2 = 0;
    double blur1 = 3;
    double blur2 = 11;
    int morph_xx, morph_yy;
    int morph_x = 1;
    int morph_y = 1;
    int morph_x2 = 1;
    int morph_y2 = 3;
    int iteration = 1;
    int canny_max = 300;
    int min_width = 8;
    int flag;
    int flag2;
    string model_path = "./1.onnx";
    dnn::Net net;
    int rect_thresh = 0;
    int blocksize = 31;
    int C = 10;
    int a = 3;
    int c = 5;
    int b = -5;
    int d = 10;
    int softmax_thresh = 0.9;
    int _h = 1;
    int _w = 1;
    int _channel = 1;
    int RGB_mode = 0;//0为默认bgr
                     //unsigned char * img
    int showimg = 1;
public:
    void * net0;
    /*
    void * net0;
    ocr() {
    this->net0 = new Net();
    }
    ~ocr() {
    delete this->net0;
    }
    */
    ocr(void);
    ~ocr(void);
    void set_print();
    void set_showimg(int x);
    void set_morph2(int x, int y);
    void set_morph(int x, int y);
    void set_morph_easy(int x);
    void set_blocksize(int _C, int _blocksize = 31);
    void set_blocksize_easy(int x);//0:
    void set_net(const string model_path);//const string 路径
                                          //void set_net_easy();
 


ocr::ocr(void)
{
    //this->net0 = new Net();
    net = cv::dnn::readNetFromONNX(model_path);
}

ocr::~ocr(void)
{
    ;
    //delete this->net0;
    //~Net();
}
void ocr::set_print()
{
    //cout<<blur <<" blur2" << "\n";
    cout << "blur is" << this->blur2;
    cout << "morph_x, morph_y :" << this->morph_x << this->morph_y << "\n";
    cout << "morph_x2 , morph_y2 :" << this->morph_x2 << this->morph_y2 << "\n";
    //cout << "model_path :" << this->model_path << "\n";
    cout << "rect_thresh :" << this->rect_thresh << "\n";
    cout << "blocksize, C :" << this->blocksize << C << "\n";
    cout << "softmax_thresh :" << this->softmax_thresh << "\n";
}

标签: c++opencv

解决方案


推荐阅读