std::string转化为QPixmap

博客围绕Qt展开,虽未给出具体内容,但推测包含Qt相关知识记录。Qt是信息技术领域重要开发工具,常用于后端开发等场景。
QPixmap headerImg;
std::string str = "";
const char *data = str.data();
int size = static_cast<int>(str.size());
headerImg.loadFromData(reinterpret_cast<const uchar*>(data),size);
this->imageItemLabel->setPixmap(headerImg);
..\..\MainWindow.cpp(28): error C2665: “op::PoseExtractorCaffe::PoseExtractorCaffe”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(19): note: 可能是“op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)” ..\..\MainWindow.cpp(28): note: “op::PoseExtractorCaffe::PoseExtractorCaffe(const op::PoseModel,const std::string &,const int,const std::vector<op::HeatMapType,std::allocator<op::HeatMapType>> &,const op::ScaleMode,const bool,const bool,const std::string &,const std::string &,const float,const bool,const bool)”: 无法将参数 7 从“op::Point<int>”转换为“const bool” ..\..\MainWindow.cpp(35): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符 ..\..\MainWindow.cpp(28): note: 尝试匹配参数列表“(op::PoseModel, const char [30], int, std::vector<op::HeatMapType,std::allocator<op::HeatMapType>>, op::ScaleMode, bool, op::Point<int>)”时 ..\..\MainWindow.cpp(116): error C2440: “<function-style-cast>”: 无法从“initializer list”转换为“op::Matrix” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix”: 没有重载函数可以转换所有参数类型 C:\openpose-prosperity\include\openpose/core/matrix.hpp(118): note: 可能是“op::Matrix::Matrix(const int,const int,const int)” ..\..\MainWindow.cpp(116): note: “op::Matrix::Matrix(const int,const int,const int)”: 无法将参数 3 从“uchar *”转换为“const int” ..\..\MainWindow.cpp(116): note: 没有使该转换得以执行的上下文 ..\..\MainWindow.cpp(116): note: 尝试匹配参数列表“(int, int, uchar *)”时 ..\..\MainWindow.cpp(117): error C2039: "copyFrom": 不是 "op::Array<float>" 的成员 C:\openpose-prosperity\include\openpose/core/array.hpp(21): note: 参见“op::Array<float>”的声明 ..\..\MainWindow.cpp(120): error C2039: "forward": 不是 "op::PoseExtractorCaffe" 的成员 C:\openpose-prosperity\include\openpose/pose/poseExtractorCaffe.hpp(16): note: 参见“op::PoseExtractorCaffe”的声明 cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -O2 -MD -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DOPENPOSE_MODEL_PATH="\"C:/openpose-prosperity/models\"" -DNDEBUG -DQT_QML_DEBUG -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_MULTIMEDIA_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I..\..\..\untitled1 -I. -IC:\openpose-prosperity\include -IC:\opencv\build\include -I"C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.44.35207\include" -IC:\Qt\6.10.0\msvc2022_64\include -IC:\Qt\6.10.0\msvc2022_64\include\QtWidgets -IC:\Qt\6.10.0\msvc2022_64\include\QtMultimedia -IC:\Qt\6.10.0\msvc2022_64\include\QtGui -IC:\Qt\6.10.0\msvc2022_64\include\QtNetwork -IC:\Qt\6.10.0\msvc2022_64\include\QtCore -Irelease -I. -I/include -IC:\Qt\6.10.0\msvc2022_64\mkspecs\win32-msvc -Forelease\ @C:\Users\admin\AppData\Local\Temp\moc_MainWindow.obj.5052.1171.jom moc_MainWindow.cpp jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile.Release [release\MainWindow.obj] Error 2 jom: C:\Users\admin\Desktop\QT\untitled1\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug\Makefile [release] Error 2 00:17:11: The command "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" terminated with exit code 2. 00:17:11: Error while building/deploying project untitled1 (kit: Desktop Qt 6.10.0 MSVC2022 64bit) 00:17:11: The kit Desktop Qt 6.10.0 MSVC2022 64bit has configuration issues which might be the root cause for this problem. 00:17:11: When executing step "Make" 00:17:11: Elapsed time: 00:08.
11-22
根据以下c++程序进行qt程序编写,实现opencv摄像头显示#include "QSCamera.h" // API鎻愪緵鐨剆aveData鍑芥暟宸插湪璇ュご鏂囦欢涓0鏄? #include <opencv2/opencv.hpp> #include <iostream> #include <thread> #include <chrono> #include <atomic> #include <fstream> #include <cstring> // 鍏ㄥ眬鍙橀噺瀹氫箟锛堜繚鎸佷笉鍙橈級 std::atomic<bool> exitFlag(false); cv::Mat currentImage; cv::Mat frame; unsigned char* rawSpectralData = nullptr; std::mutex mtx; cv::VideoCapture cap(0); // 璇诲彇.qs鏍煎紡鍏夎氨鏁版嵁锛堜繚鎸佷笉鍙橈紝閫傞厤API淇濆瓨鐨?qs鏂囦欢鏍煎紡锛? cv::Mat readQSData(const std::string& filename) { std::ifstream qsFile(filename, std::ios::binary); if (!qsFile.is_open()) { std::cerr << "閿欒锛氭棤娉曟墦寮€.qs鏂囦欢 " << filename << std::endl; return cv::Mat(); } // 鑾峰彇鏂囦欢澶у皬骞堕獙璇侊紙API淇濆瓨鐨?qs鏂囦欢浠嶄负1600*1200*2瀛楄妭锛? qsFile.seekg(0, std::ios::end); int fileSize = qsFile.tellg(); qsFile.seekg(0, std::ios::beg); const int expectedSize = 1200 * 1600 * 2; if (fileSize != expectedSize) { std::cerr << "璀﹀憡锛?qs鏂囦欢澶у皬涓嶇锛堝疄闄咃細" << fileSize << "锛岄鏈燂細" << expectedSize << "锛? << std::endl; } // 璇诲彇API淇濆瓨鐨勪簩杩涘埗鏁版嵁 unsigned char* data = new unsigned char[expectedSize]; qsFile.read(reinterpret_cast<char*>(data), expectedSize); qsFile.close(); // 杞崲涓篛penCV 16浣嶅崟閫氶亾鐭╅樀锛堟棤棰濆澶勭悊锛岄€傞厤API杈撳嚭鏍煎紡锛? cv::Mat spectralMat(1200, 1600, CV_16UC1, data); cv::Mat result; spectralMat.copyTo(result); delete[] data; return result; } // 鍏夎氨鐩告満鍥炶皟鍑芥暟锛堜繚鎸佷笉鍙橈紝璐熻矗鎺ユ敹鍘熷鏁版嵁骞堕澶勭悊鏄剧ず锛? void callBack(unsigned char* img) { std::lock_guard<std::mutex> lock(mtx); // 缂撳瓨鍘熷鏁版嵁锛屼緵API鐨剆aveData鍑芥暟浣跨敤 rawSpectralData = img; // 澶勭悊16浣嶆暟鎹负8浣嶆樉绀哄浘 cv::Mat image16UC1(1200, 1600, CV_16UC1, img); cv::Mat image8UC1; image16UC1.convertTo(image8UC1, CV_8UC1, 1.0 / 64); currentImage = image8UC1.clone(); } // 鏄剧ず绾跨▼鍑芥暟锛堜繚鎸佷笉鍙橈紝璋冪敤API鐨剆aveData鍑芥暟锛? void displayThreadFunc() { // 鍒涘缓骞惰皟鏁寸獥鍙? cv::namedWindow("Real-time Image", cv::WINDOW_NORMAL); cv::namedWindow("camera", cv::WINDOW_NORMAL); cv::namedWindow("QS Data Preview", cv::WINDOW_NORMAL); cv::resizeWindow("Real-time Image", 320, 240); cv::resizeWindow("camera", 320, 240); cv::resizeWindow("QS Data Preview", 320, 240); int key = 0; static int frameCount = 0; while (!exitFlag) { cv::Mat currentDisplay; unsigned char* currentRawData = nullptr; // 瀹夊叏璇诲彇鍏变韩璧勬簮 { std::lock_guard<std::mutex> lock(mtx); if (!currentImage.empty()) { currentDisplay = currentImage.clone(); } currentRawData = rawSpectralData; } // 鏄剧ず鍥惧儚涓庢寜閿鐞? if (!currentDisplay.empty()) { cv::imshow("Real-time Image", currentDisplay); // 鏅€氱浉鏈哄浘鍍忓鐞? cap >> frame; if (!frame.empty()) { cv::flip(frame, frame, -1); cv::imshow("camera", frame); } key = cv::waitKey(1); if (key == 27) { // ESC閫€鍑? exitFlag = true; } else if (key == 32) { // 绌烘牸閿繚瀛橈紙璋冪敤API鐨剆aveData锛? // 鏋勯€犲熀纭€璺緞锛堜笉鍚悗缂€锛孉PI浼氳嚜鍔ㄦ坊鍔?qs锛? std::string basePath = "/home/lckfb/Desktop/data/QSFrame_" + std::to_string(frameCount); // 1. 淇濆瓨鍏夎氨鏄剧ず鍥撅紙PNG锛? std::string imgFilename = basePath + ".png"; cv::imwrite(imgFilename, currentDisplay); std::cout << "鍏夎氨鍥惧儚淇濆瓨涓?" << imgFilename << std::endl; // 2. 淇濆瓨鏅€氱浉鏈哄浘鍍忥紙PNG锛? std::string vFilename = "/home/lckfb/Desktop/data/VFrame_" + std::to_string(frameCount) + ".png"; cv::imwrite(vFilename, frame); std::cout << "鏅€氬浘鍍忎繚瀛樹负 " << vFilename << std::endl; // 3. 璋冪敤API鎻愪緵鐨剆aveData鍑芥暟淇濆瓨.qs鏂囦欢 if (currentRawData) { // 鐩存帴浼犲師濮嬫暟鎹拰鍩虹璺緞锛孉PI鍐呴儴澶勭悊锛? // - 妫€鏌ユ暟鎹湁鏁堟€? // - 娣诲姞.qs鍚庣紑 // - 浜岃繘鍒跺啓鍏ワ紙绗﹀悎1600*1200*2瀛楄妭鏍煎紡锛? saveData(currentRawData, basePath); } // 4. 棰勮API淇濆瓨鐨?qs鏂囦欢锛堥獙璇佷繚瀛樼粨鏋滐級 std::string qsFilename = basePath + ".qs"; cv::Mat qsData = readQSData(qsFilename); if (!qsData.empty()) { cv::Mat qsPreview; qsData.convertTo(qsPreview, CV_8UC1, 1.0 / 64); cv::imshow("QS Data Preview", qsPreview); } frameCount++; } } else { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } cv::destroyAllWindows(); } int main() { // 鍒濆鍖栧厜璋辩浉鏈猴紙渚濊禆QSCamera.h鐨凙PI鍑芥暟锛? regeditCallBack(callBack); openCamera("/dev/video9"); // 閰嶇疆鏅€氱浉鏈? cap.set(cv::CAP_PROP_FRAME_WIDTH, 320); cap.set(cv::CAP_PROP_FRAME_HEIGHT, 240); cap.set(cv::CAP_PROP_FPS, 30); if (!cap.isOpened()) { std::cerr << "鏃犳硶鎵撳紑鏅€氱浉鏈猴紒" << std::endl; return -1; } // 鍚姩鏄剧ず绾跨▼ std::thread displayThread(displayThreadFunc); // 鎿嶄綔鎻愮ず std::cout << "鎸塃SC閿€€鍑虹▼搴?..\n"; std::cout << "鎸夌┖鏍奸敭淇濆瓨鍏夎氨鍥惧儚銆佹櫘閫氬浘鍍忓拰.qs鍏夎氨鏁版嵁锛堣皟鐢ˋPI锛?..\n"; // 绛夊緟绾跨▼缁撴潫 displayThread.join(); // 璧勬簮娓呯悊锛堜緷璧朡SCamera.h鐨凙PI鍑芥暟锛? closeCamera(); cap.release(); return 0; }
09-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值