OpenCV filter2D C+中的负值+; 我试图在C++中实现一些视频帧的方向梯度直方图。我使用filter2D对帧图像进行卷积,但结果值似乎为0。如何让filter2D也给出负值
下面是一段代码:OpenCV filter2D C+中的负值+; 我试图在C++中实现一些视频帧的方向梯度直方图。我使用filter2D对帧图像进行卷积,但结果值似乎为0。如何让filter2D也给出负值,c++,opencv,C++,Opencv,下面是一段代码: // Function that gets the histogram of gradients for a single video file int HOG(string filename) { static int frames_read = 0; VideoCapture cap(filename); if(!cap.isOpened()) // check if we succeeded return -1; Mat
// Function that gets the histogram of gradients for a single video file
int HOG(string filename)
{
static int frames_read = 0;
VideoCapture cap(filename);
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat image;
namedWindow(filename,1);
// Read through frames of video
for(;;)
{
Mat frame;
float histogram[NUM_BINS * SPACIAL_X * SPACIAL_Y] = {0};
cap >> frame; // Get a new frame from camera
if(frame.empty())
break;
cvtColor(frame, image, CV_BGR2GRAY);
// Set up gradient kernels
float kernelX[9] = {0, 0, 0, -1.0, 0, 1.0, 0, 0, 0};
float kernelY[9] = {0, -1.0, 0, 0, 0, 0, 0, 1.0, 0};
Mat filterX(3, 3, CV_32F, kernelX);
Mat filterY(3, 3, CV_32F, kernelY);
Mat gradientX;
Mat gradientY;
// Apply gradients
filter2D(image, gradientX, CV_32F, filterX, Point (-1, 1), 0, BORDER_DEFAULT);
filter2D(image, gradientY, CV_32F, filterY, Point (-1, 1), 0, BORDER_DEFAULT);
}
}
将图像转换为浮点值也要检查一下,我刚才使用了一些类似于
p=gradientX.ptr(idx)
的东西来迭代gradientX和gradientY mats,当你说将浮点图像转换为灰度值将裁剪负面结果时,这是否意味着我不应该在应用渐变之前从BGR转换为灰色?等等,我明白了,我应该使用类似gradientX.ptr(idx)