以下是相关代码:
void store::Hidden_Extract_Package(store::IPackage& _P, std::vector<store::IPackage> &_vector_of_extracted, std::string &_return_msg) {
// get data from .txt and .jpg, put on heap, update pointers to point to this data
std::vector<std::string> *text_ptr = new std::vector<std::string>(20); // allocate memory on heap for text data
cv::Mat* image_ptr = new cv::Mat;
_P.SetTextDataPtr(text_ptr);
_P.SetImageDataPtr(image_ptr);
// contains adress of a vector that stores each text line in a string
// text file is limited to 20 lines
for (const auto &entry : std::filesystem::directory_iterator(_P.GetParentPath())) { // find all children: will contain .txt and .jpg dir
std::filesystem::path child_path = entry.path();
std::string extension = (child_path.extension()).string(); // is this jpg or txt file?
if (extension == ".txt") {
...
}
if (extension == ".jpg") {
std::string path_name = entry.path().string();
_return_msg = path_name;
if (!path_name.empty()) {
*image_ptr = cv::imread(path_name, 0); // read in grayscale
/* exception thrown:
Debug Assertion Failed!
Program: ...\source\repos\StorageEngine\_build\x64\Release\StorageGUI.exe
File: minkernel\crts\ucrt\src\appcrt\stdio\fopen.cpp
Line: 30
Expression: file_name != nullptr
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
weird thing is that the path_name is valid
*/
}
,然后通过库/接口使用此功能的GUI:
store::Extract_Package(selected_package, m_vector_of_extracted, test);
... (displaying text, this works fine)
// display image
// use QGraphicsView: needs QGraphicsScene, needs QGraphicsPixmapItem that needs QImage
cv::Mat raw_image = *(m_vector_of_packages[table_row].GetImageDataPtr());
//// opencv uses a diffrent format than QImage so will have to transform:
//QImage image = QImage(raw_image.data, raw_image.cols, raw_image.rows, QImage::Format_Mono);
//QPixmap pixmap = QPixmap::fromImage(image, Qt::AutoColor); // something doesnt work yet...
//pixmap = pixmap.scaled(ui.labelImage->width(), ui.labelImage->height());
//ui.labelImage->setPixmap(pixmap);
我想我早就开始工作了,然后没有引发异常,但是图像仍然不会显示,但是我丢失了这段代码。我一直在寻找一段时间,但我不知道如何解决。