sách gpt4 ai đã đi

opencv - OpenCV:如何使用cvSobel?

In lại 作者:行者123 更新时间:2023-12-02 17:52:12 32 4
mua khóa gpt4 Nike

我正在尝试使用OpenCv 2.4.5从边缘查找渐变方向,但是我在使用cvSobel()时遇到问题,以下是错误消息和我的代码。我在某处读到它可能是由于浮点(??)之间的转换,但我不知道如何解决它。有帮助吗?

#include 
#include
#include
#include
#include

#include
#include
#include "stdio.h"

using namespace cv;
sử dụng không gian tên std;

int chính()
{
Mat im = imread("test1.jpg");
if (im.empty()) {
cout << "Cannot load image!" << endl;
}
Mat *dx, *dy;
dx = new Mat( Mat::zeros(im.rows, im.cols, 1));
dy = new Mat( Mat::zeros(im.rows, im.cols, 1));

imshow("Image", im);

// Convert Image to gray scale
Mat im_gray;
cvtColor(im, im_gray, CV_RGB2GRAY);
imshow("Gray", im_gray);

//trying to find the direction, but gives errors here
cvSobel(&im_gray, dx, 1,0,3);


waitKey(0);
trả về 0;
}

1 Câu trả lời

您正在混合使用C++和C api。 cv::Mat来自C++ API,而CvArr*来自C API。
在这里,您正在C++类上使用C api cvSobel.

//trying to find the direction, but gives errors here
cvSobel(&im_gray, dx, 1,0,3);

如果您这样做会怎样?
cv::Sobel( im_gray, dx, im_gray.depth(), 1, 0, 3);

biên tập
并声明
Mat dx;
Mat dy;

我认为这可能会解决您的问题,实际上您的代码编译让我很惊讶。

关于opencv - OpenCV:如何使用cvSobel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982226/

32 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com