2
我目前正在嘗試序列化和反序列化openCV Mat,以便我可以使用Boost將客戶端的幀發送到服務器。我遇到的問題是,當我反序列化圖像時,它會給出不同顏色的重疊圖像。我不知道爲什麼會發生這種情況。任何幫助將非常感激。對不起,我無法發佈圖片,因爲我沒有足夠的徽章。主cv :: Mat的序列化給出奇怪的結果
#include "serialization.h"
using namespace std;
using namespace cv;
using namespace boost;
Mat frame;
void saveMat(Mat& m, string filename);
void loadMat(Mat& m, string filename);
int main(int argc, const char * argv[]) {
// insert code here...
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system
cvNamedWindow("serialization", 2); //Create window
while(1) {
frame = cvQueryFrame(capture);
saveMat(frame, "archive.bin");
cv::Mat frame2;
loadMat(frame2, "archive.bin");
IplImage tmp = frame2;
cvShowImage("serialization", &tmp);
}
return 0;
}
void saveMat(Mat& m, string filename) {
ofstream ofs(filename.c_str());
archive::binary_oarchive oa(ofs);
oa << m;
}
void loadMat(Mat& m, string filename) {
ifstream ifs(filename.c_str());
archive::binary_iarchive ia(ifs);
ia >> m;
}
enter code here
非常感謝,原來我在調用saveMat函數之前添加了這個。 –
cvtColor(frame,frame,CV_BGR2BGRA); –
你知道這是爲什麼嗎?如果有任何問題,我正在使用MacBook Pro的網絡攝像頭。 –