【发布时间】:2021-08-12 22:55:57
【问题描述】:
我编写了一个简单的 Oct 文件来包装 OpenCV 函数。这是我的代码:-
#include <octave/oct.h>
#include <opencv2/imgproc.hpp>
DEFUN_DLD (cornerHarris, args, , "Harris Corner Detector")
{
// Processing arguments
if(args.length()<4){
print_usage();
}
Matrix octInMat = args(0).matrix_value();
int blockSize = args(1).int_value();
int kSize = args(2).int_value();
double k = args(3).double_value();
int borderType = args(4).int_value();
// Dimentions
dim_vector dims = octInMat.dims();
int h = dims.elem(0);
int w = dims.elem(1);
// OpenCV Matrix
cv::Mat cvInMat = cv::Mat::zeros(h,w, CV_8U);
cv::Mat cvOutMat = cv::Mat::zeros(h,w, CV_32FC1);
// Converting Octave Matrix to OpenCV Matrix
for (int r=0;r<h;r++)
{
for(int s=0;s<w;s++)
{
cvInMat.at<int>(r,s) = octInMat(r,s);
}
}
cv::cornerHarris( cvInMat, cvOutMat, blockSize, kSize, k, borderType );
// Converting OpenCV Matrix to Octave Matrix
Matrix octOutMat = Matrix(dim_vector(h,w));
for (int r=0;r<h;r++)
{
for(int s=0;s<w;s++)
{
octOutMat(r,s) = cvOutMat.at<double>(r,s);
}
}
return octave_value(octOutMat);
}
但是当w 变量的值增加时,我收到了分段错误。有没有什么捷径可以在不循环的情况下转换矩阵?或者有没有办法解决分段错误?
文档:-
【问题讨论】:
-
你试过在调试器下运行吗?
-
@CrisLuengo 我用调试标志编译了它。 (
mkoctfile -lopencv_core -lopencv_imgproc -g ./includes/+cv/cornerHarris.cc -o ./includes/+cv/cornerHarris.oct)。但仍然得到没有任何细节的分割错误。还有其他方法可以调试.oct文件吗?