目的:利用sse求取图像的垂直和水平梯度图,加快求梯度图的运算速度
代码实现:
#include "stdio.h"
#include "opencv2\\opencv.hpp"
#include "sse.h"
using namespace std;
using namespace cv;
int main()
{
//[1] 读取图像,并把图像转化成灰度图
Mat img = imread("003.jpg");
if (NULL == img.data)
{
printf("read img error!\n");
getchar();
}
Mat imgGray;
cvtColor(img, imgGray,CV_BGR2GRAY);
namedWindow("灰度图", 0);
imshow("灰度图", imgGray);
waitKey(0);
// [2] 将图像数据转化成浮点型数据
int nHeight = imgGray.rows;
int nWidth = imgGray.cols;
int nWidthDst = 0;
float* pData = (float*)_aligned_malloc(nWidth* nHeight * sizeof(float), 16);
memset(pData, 0, nWidth* nHeight* sizeof(float));
for (int i = 0; i < nHeight; i++)
{
for (int j = 0; j < nWidth; j++)
{
pData[i*nWidth + j] = (float)imgGray.data[i*nWidt