成功打印每个元素后出现 OpenCV 分割错误
OpenCV segmentation fault after successfully printing each element
此代码在执行时显示预期的输出,但在末尾打印分段错误(核心转储(:
int main(){
Mat src(100,100,CV_32F,0);
for(int i=0 ; i < src.rows ; i++ ){
for(int j=0 ; j < src.cols ; j++ ){
src.at<float>(i,j)=0;
}
}
for(int i=0 ; i < src.rows ; i++ ){
for(int j=0 ; j < src.cols ; j++ ){
cout<<src.at<float>(i,j)<<" ";
}
cout<<endl;
}
return 0;
}
请编写最小的工作示例,以便我们可以简单地复制和粘贴代码并对其进行测试。
#include <iostream>
#include <opencv2/core.hpp>
using namespace std;
using namespace cv;
int main() {
/* Mat src(100, 100, CV_32F, 0); */
Mat src(100, 100, CV_32F, Scalar(0));
for (int i = 0; i < src.rows; i++) {
for (int j = 0; j < src.cols; j++) {
src.at<float>(i, j) = 0;
}
}
for (int i = 0; i < src.rows; i++) {
for (int j = 0; j < src.cols; j++) {
cout << src.at<float>(i, j) << " ";
}
cout << endl;
}
return 0;
}
问题似乎是opencv
比较,在opencv2/core/mat.inl.hpp
的第 500 行CV_Assert
,data
相对于NULL
。基本上,当您在构造函数中给出非零值(例如1
(或使用其Scalar
数据类型来提供值时,您的代码就可以正常工作。
顺便说一句,我没有收到段错误,而只是在链接opencv_core
后尝试运行代码时出现CV::Exception
。
相关文章:
- 如何在使用OpenCV C++应用K均值后提取分割图像
- 在不使用经过训练的模型的情况下检测/分割面部和面部特征:openCV C++
- OPENCV C 中的分割故障误差
- 如何在OpenCV中对连接组件进行分割
- C++/openCV - 为什么显示图像会产生 Linux 分割错误?(打开CV错误?
- 成功打印每个元素后出现 OpenCV 分割错误
- OPENCV 3.3-使用GPU函数时分割故障
- 分割故障OpenCV Linux C
- 如何在OpenCV中实现颜色分割以及前景检测
- 分割故障原因未知OPENCV
- 在opencv c++中查找图像卷积时出现分割错误(核心转储)
- 比较 descriptor.type 和 descriptor.cols 后的 OpenCV 分割错误
- opencv 中向量<向量>中的分割错误<Point>
- OpenCV:如何使用阈值正确分割图像/使用二进制图像对原始图像进行分割
- 使用OpenCV进行红外图像分割
- OpenCV背景分割/从单个图像中减去
- OpenCV分割图像成矩形
- 使用OpenCV和c++将图像帧分割成8*8进行DCT
- Android OpenCV颜色分割显示在ImageView上
- OpenCV中前景-背景分割方法的区别