总是出错
#in[i]clude<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
void convolution(Mat& image, Mat& result, float* Template, int widthTemplate, int heightTemplate);
int main()
{
Mat srcImage = imread(“boldt.jpg”,0);
Mat dstImage(srcImage.size(), CV_32FC1);
imshow(“1”, srcImage);
float Template[9] = { -1, 0, 1,
-1, 0, 1,
-1, 0, 1 };
convolution(srcImage, dstImage, Template, 3, 3);
dstImage.convertTo(dstImage, CV_8UC1);
imshow(“2”, dstImage);
waitKey(0);
return 0;
}
void convolution(Mat& image, Mat& result, float* Template, int widthTemplate, int heightTemplate)
{
int halfWidth = widthTemplate / 2;
int halfHeight = heightTemplate / 2;
for (int y = halfHeight; y < image.rows – halfHeight; y++)
{
for (int x = halfWidth; y < image.cols – halfWidth; x++)
{
float curDx = 0;
for (int j = -halfHeight; j <= halfHeight; j++)
{
for (int i = -halfWidth; i <= halfWidth; i++)
{
curDx += image.at<uchar>(y + j, x + i)**(Template + (j+halfHeight)*widthTemplate + i + halfWidth);
}
}
result.at<float>(y, x) = curDx;
}
}
}
#in[i]clude<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
void convolution(Mat& image, Mat& result, float* Template, int widthTemplate, int heightTemplate);
int main()
{
Mat srcImage = imread(“boldt.jpg”,0);
Mat dstImage(srcImage.size(), CV_32FC1);
imshow(“1”, srcImage);
float Template[9] = { -1, 0, 1,
-1, 0, 1,
-1, 0, 1 };
convolution(srcImage, dstImage, Template, 3, 3);
dstImage.convertTo(dstImage, CV_8UC1);
imshow(“2”, dstImage);
waitKey(0);
return 0;
}
void convolution(Mat& image, Mat& result, float* Template, int widthTemplate, int heightTemplate)
{
int halfWidth = widthTemplate / 2;
int halfHeight = heightTemplate / 2;
for (int y = halfHeight; y < image.rows – halfHeight; y++)
{
for (int x = halfWidth; y < image.cols – halfWidth; x++)
{
float curDx = 0;
for (int j = -halfHeight; j <= halfHeight; j++)
{
for (int i = -halfWidth; i <= halfWidth; i++)
{
curDx += image.at<uchar>(y + j, x + i)**(Template + (j+halfHeight)*widthTemplate + i + halfWidth);
}
}
result.at<float>(y, x) = curDx;
}
}
}
解决方案
80
for (int x = halfWidth; y < image.cols – halfWidth; x++)
能否应该是
for (int x = halfWidth; x < image.cols – halfWidth; x++)
能否应该是
for (int x = halfWidth; x < image.cols – halfWidth; x++)