Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在OpenCV中放大数组_Opencv_Point Cloud Library - Fatal编程技术网

在OpenCV中放大数组

在OpenCV中放大数组,opencv,point-cloud-library,Opencv,Point Cloud Library,我想制作一个包含X、Y、Z、RGBA和标签字段的PCD文件。现在我有一个XYZRGBA,PCD文件。包括640*480点。另一方面,我有另一个文件,其中包含320*256个数字,表示分割图像中的标签。我想放大标签阵列,并将其添加到当前PCD文件中,以创建具有相应x、y、z、rgba和标签信息的新PCD文件。此PCD文件将与分割图像相关。 这是我的尝试。 Label是包含标签信息的文件名,首先我将其转换为OpenCV矩阵,现在我想将其放大到640*480,然后将其添加到当前的xyzrgba、pcd

我想制作一个包含X、Y、Z、RGBA和标签字段的PCD文件。现在我有一个XYZRGBA,PCD文件。包括640*480点。另一方面,我有另一个文件,其中包含320*256个数字,表示分割图像中的标签。我想放大标签阵列,并将其添加到当前PCD文件中,以创建具有相应x、y、z、rgba和标签信息的新PCD文件。此PCD文件将与分割图像相关。 这是我的尝试。 Label是包含标签信息的文件名,首先我将其转换为OpenCV矩阵,现在我想将其放大到640*480,然后将其添加到当前的xyzrgba、pcd文件中。再次放大后,我将生成的OpenCV矩阵转换为名为“array”的普通矩阵,用于添加到当前PCD数据中

cv::Mat LabelsMat=cv::Mat(320,256, CV_32SC1, label); 
cv::Mat OriginalLabels=cv::Mat::zeros(320,256, CV_32SC1);
LabelsMat.copyTo(OriginalLabels);    
cv::Mat UpScaledLabels=cv::Mat::zeros(640, 480, CV_32FC1); 
cv::resize(OriginalLabels, UpScaledLabels, UpScaledLabels.size(), 0, 0,cv::INTER_NEAREST); 
std::vector<int> array;
array.assign((int*)UpScaledLabels.datastart, (int*)UpScaledLabels.dataend);
cv::Mat LabelsMat=cv::Mat(320256,cv_32SC1,标签);
cv::Mat OriginalLabels=cv::Mat::Zero(320256,cv_32SC1);
标签材料副本(原始标签);
cv::Mat UpScaledLabels=cv::Mat::Zero(640480,cv_32FC1);
cv::resize(原始标签、UpScaledLabels、UpScaledLabels.size()、0、0、cv::INTER_最近);
std::矢量阵列;
分配((int*)UpScaledLabels.datastart,(int*)UpScaledLabels.dataend);

但是有一些问题。当我制作这个新的PCD文件时,只想看到图像的一段,例如4,我会看到一个错误的形状,根据我的基本图像,这与第4段非常不同。我确信问题是因为这部分和上面的代码。有人能帮我找到这个问题吗?我感谢你的宝贵帮助

好了,终于有时间了

查看生成的Mat对象总是很好的,只需使用cv::imshow或cv::imwrite并相应地缩放数据即可

使用此代码(基本上是您自己的固定数组写入代码):

你可以得到这个看起来更好的垫子:

但和你的另一张照片相比,那张照片不知怎么旋转了


CV_32FC1
应该是
CV_32SC1
,但这不应该是问题,因为OpenCV将重新分配矩阵本身。您可以添加变量
标签的声明吗?我觉得你的尺寸调整很合适。。。请检查调整大小后
UpScaledLabels
是否连续?是否确实使用了
array。分配
的方法是否正确?我猜它使用迭代器而不是指针。。。请尝试在垫子上循环,并将条目推回,只是为了调试…非常感谢您的回答。我的标签是一个“.dat”文件的名称,它的大小是:640*256,但由于每两个数字之间有一个空格,所以数据的大小是:320*256。我用这条指令读取它,并将数据作为整数,用作名为label===>ifstream in(“My_Labels.dat”)的矩阵中的段名称;for(i=0;i<320;i++)for(j=0;j<256;j++){in>>标签[i][j];}in.close();对不起,你说的“调整大小后检查上标标签是否连续”是什么意思?提前感谢:)那么“标签”是整数**?创建LabelMat时,openCV mat需要一个int*作为输入。尝试cv::Mat LabelsMat=cv::Mat(320256,cv_32SC1,&label[0][0]);真的非常感谢你。我现在就试试:)代码工作正常。仅在交换尺寸后的第二个代码部分中,它应该是:“cv::Mat LabelsMat=cv::Mat(256320,cv_32SC1,label);“现在我有了单独的第4段,正如我希望的那样,以正确的方式:”,非常感谢,上帝保佑你:)谢谢!这是我这边的复制/粘贴错误。。。太愚蠢了:D编辑了那个。。。希望你不要浪费太多时间在我的答案中找出那个错误--
int label[320][256];

std::ifstream in("../inputData/UPSCALE_data.dat"); 
for (int i = 0; i < 320; i++) 
    for (int j = 0;j< 256; j++) 
    { 
        in >> label[i][j]; 
    } 
in.close();

// create Mat with label input:
cv::Mat LabelsMat=cv::Mat(320,256, CV_32SC1, label); 

cv::Mat OriginalLabels = LabelsMat.clone(); // you could instead work on the non-copied data, if you liked to...

// upscale:
cv::Mat UpScaledLabels; // no need to allocate memory here during testing
cv::resize(OriginalLabels, UpScaledLabels, cv::Size(640, 480), 0, 0,cv::INTER_NEAREST); 

std::vector<int> marray;
marray.reserve(UpScaledLabels.cols*UpScaledLabels.rows);
for(int j=0; j<UpScaledLabels.rows; ++j)
    for(int i=0; i<UpScaledLabels.cols; ++i)
    {
        marray.push_back(UpScaledLabels.at<int>(j,i));
    }

// now here marray has information about the upscaled image.


cv::Mat convertedCorrect;
UpScaledLabels.convertTo(convertedCorrect, CV_8UC1);

cv::imwrite("../outputData/UPSCALED_RESULT_ORIG.png", convertedCorrect*50);
int label[320][256];

std::ifstream in("../inputData/UPSCALE_data.dat"); 
for (int i = 0; i < 320; i++) 
    for (int j = 0;j< 256; j++) 
    { 
        in >> label[i][j]; 
    } 
in.close();

// create Mat with label input: HERE THE DIMENSIONS ARE SWAPPED
cv::Mat LabelsMat=cv::Mat(256,320, CV_32SC1, label); 

cv::Mat OriginalLabels = LabelsMat.clone(); // you could instead work on the non-copied data, if you liked to...

// upscale:
cv::Mat UpScaledLabels; // no need to allocate memory here during testing
cv::resize(OriginalLabels, UpScaledLabels, cv::Size(640, 480), 0, 0,cv::INTER_NEAREST); 

std::vector<int> marray;
marray.reserve(UpScaledLabels.cols*UpScaledLabels.rows);
for(int j=0; j<UpScaledLabels.rows; ++j)
    for(int i=0; i<UpScaledLabels.cols; ++i)
    {
        marray.push_back(UpScaledLabels.at<int>(j,i));
    }

// now here marray has information about the upscaled image.


cv::Mat convertedCorrect;
UpScaledLabels.convertTo(convertedCorrect, CV_8UC1);

cv::imwrite("../outputData/UPSCALED_RESULT_CORRECTED.png", convertedCorrect*50);