【发布时间】:2021-11-27 10:32:09
【问题描述】:
我正在文件 .hpp 中编写一个类,我正在使用 VS2019 和 opencv 3.4.1。 它返回此错误:
Exception thrown: read access violation.
this->p was nullptr. at line 1419 of file mat.inl.hpp
当我只编译那个 .hpp 文件时,它成功且没有错误,但是如果我尝试在另一个文件中声明这个类,它会返回这个错误:
这就是我的文件 .hpp 的样子
#pragma once
#include "Header_1.h"
class GUI_1
{
private:
//Create a black image
Mat imgBlank = Mat::zeros(original.size(), CV_8UC3);
//Take size original to 2 part
int height = original.size().height;
int width = original.size().width;
public:
//Sources img (input)
Mat original;
//extension coordinate variable for tracking object
int posX;
int posY;
//last line of input
//color for cross hair and coordinate
double red = 0;
double green = 255;
double blue = 255;
//function
Mat crosshair()
{
// Crate blank img
Mat img = imgBlank;
//properties
int length = 10;
//draw crosshair
//horizon
line(img, Point(posX - length, posY), Point(posX + length, posY), Scalar(blue, green, red), 1);
//vertical
line(img, Point(posX, posY - length), Point(posX, posY + length), Scalar(blue, green, red), 1);
return img;
}
Mat imgCoordinate()
{
//blank img
Mat img = imgBlank;
//coordinate of text with object
const int subX = 2;
const int subY =2;
//put coordinate
string Text = "X=" + to_string(posX) + "Y=" + to_string(posY);
putText(img, Text, Point(posX + subX, posY + subY), FONT_HERSHEY_COMPLEX, 1, Scalar(blue, green, red), 1);
return img;
}
//Create imgGUI for show (output)
Mat imgGUI = imgBlank + crosshair() + imgCoordinate();
};
【问题讨论】: