gpt4 book ai didi

c++ - openCV 创建不同大小的 3D 矩阵

转载 作者:行者123 更新时间:2023-11-28 06:18:32 26 4
gpt4 key购买 nike

据此 http://answers.opencv.org/question/15917/how-to-access-data-from-a-cvmat/ 我尝试创建一个 3D 矩阵

void AutomaticMacbethDetection::DrawMacbethROI(ColorCheckerBatchRGB ColorCheckerBatchRGB, int *** raw_frame,int _width, int _height,int colorOrder)
{
cv::Mat src;
if (colorOrder == -1)
{
const int sizes[3]={_height,_width,3};
src = cv::Mat::zeros(3, sizes, CV_32F);

}else
{
const int sizes[3]={_height,_width,1};
src = cv::Mat::zeros(3, sizes, CV_32F);
}

std::vector<float> channel;
if (colorOrder == -1)
{
for (int w = 0; w < _width; w++)
{
for (int h = 0; h < _height; h++)
{
float temp =raw_frame[h][w][0];
channel.push_back(temp);
src.at<float>(h,w,0) = temp;
src.at<float>(h,w,1) = raw_frame[h][w][1];
src.at<float>(h,w,2) = raw_frame[h][w][2];
}
}
}
else
{
for (int w = 0; w < _width; w++)
{
for (int h = 0; h < _height; h++)
{
float temp =raw_frame[h][w][0];
channel.push_back(temp);
src.at<float>(h,w,0) = temp;
}
}
float divider = Utilities::tprctile(channel,99.2);
src = src/divider;
}

cv::imshow("test", src);
cv::waitKey(0);

我的函数同时支持 RGB 和原始图像,因此我需要创建一个 100x100x1 矩阵或 100x100x3 矩阵,具体取决于图像类型。

但是我在 imshow() 中遇到异常

OpenCV Error: Assertion failed (p[-1] <= 2) in cv::Mat::MSize::operator (), file
C:\buildslave64\win64_amdocl\2_4_PackSlave-win64-vc11-shared\opencv\modules\cor
e\include\opencv2/core/mat.hpp, line 712

你能解释一下问题是什么吗?

最佳答案

在我看来,您正在尝试在这两种情况下设置 3 层零垫:

const int sizes[3]={_height,_width,1};
src = cv::Mat::zeros(3, sizes, CV_32F);

C++:static MatExpr Mat::zeros(int ndims, const int* sz, int type) 指出第一个参数是维度。如果您想要一层垫子,这里应该为 1。

关于c++ - openCV 创建不同大小的 3D 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com