此示例代码将显示正确创建的图像,但将保存仅包含黑色像素的png.Mat是CV_32FC3格式,因此3个浮点数通道.
我发现的已回答的问题涉及图像处理问题或转换不正确或使用各种压缩保存在jpeg中.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
int i = 0;
int j = 0;
Vec3f intensity;
cv::Mat imageF;
imageF= cv::Mat::zeros(36,36,CV_32FC3);
for(j=0;j<imageF.cols;++j){
for(i=0;i<imageF.rows;++i){
intensity = imageF.at<Vec3f>(j, i);
intensity.val[2] = 0.789347;
intensity.val[1] = 0.772673;
intensity.val[0] = 0.692689;
imageF.at<Vec3f>(j, i) = intensity;
}}
imshow("Output", imageF);
imwrite("test.png", imageF);
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
需要进行哪些更改才能使其按预期保存?
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main() {
int i = 0;
int j = …Run Code Online (Sandbox Code Playgroud) 在boost 属性树的文档中,有一个正确使用的示例,在此处或在包中给出 libs/property_tree/examples/debug_settings.cpp.
我想知道的是关于这struct debug_settings条线.为什么要把它作为结构而不是类?它甚至有两个成员函数,load(...)和save(...).我认为提升作者有充分的理由这样做,并且它与...效率有某种关系,即使结构和类在"技术上"相同?
从列出的版权年份,我可以猜测这可能是C++ 98,C++ 03或C++ 0x,因此使用结构而不是类的原因至少来自于前C++ 11观点.
// ----------------------------------------------------------------------------
// Copyright (C) 2002-2006 Marcin Kalicinski
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// For more information, see www.boost.org
// ----------------------------------------------------------------------------
//[debug_settings_includes
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
#include <iostream>
namespace pt = …Run Code Online (Sandbox Code Playgroud)