目的是把输入的200*200的图像进行一次行变换
首先把输入图像转换成灰度图像,然后初始化一个同样大小和类型的dst
将灰度图像的相邻两个列的像素的和除以根号2,放在dst的左边;相邻两个列的像素的差除以根号2,放在dst的右边。
比如(0,0)和(0,1)的和除以根号2,放在dst的(0,0);(0,2)和(0,3)的和除以根号2,放在dst的(0,1);依次类推
程序在运行到for循环那里就不运行了,错误列表里面也没有信息。
麻烦各位前辈帮忙看看是什么地方出了问题
#include <iostream>
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace cv;
int main()
{
//初始化矩阵
Mat src, gray_src, dst;
src = imread("1.jpg");
//创建图像窗口
std::string src_title = "原图像";
std::string gray_title = "灰度图像";
std::string dst_title = "输出图像";
namedWindow(src_title, WINDOW_NORMAL);
namedWindow(gray_title, WINDOW_NORMAL);
namedWindow(dst_title, WINDOW_NORMAL);
////图像填充
//copyMakeBorder(src, src_add, 2,2,0,0, BORDER_REFLECT);
//int width = src_add.rows;
//int height = src_add.cols;
//读取原图像宽高并显示原图像
int width = src.rows;
int height = src.cols;
std::cout << "width: " << width << " height: " << height << std::endl;
imshow(src_title, src);
//将原图像转化为灰度图像
cvtColor(src, gray_src, COLOR_BGR2GRAY);
//创建一个输出图像矩阵,大小类型与原图像一致
dst.create(gray_src.size(), gray_src.type());
imshow(gray_title, gray_src);
//haar行变换
for (int i = 0; i < gray_src.cols; i++)
{
for (int j = 0; j < gray_src.rows; j++)
{
dst.at<double>(j, i) = (gray_src.at<double>(j * 2, i) + gray_src.at<double>(j * 2 + 1, i)) / sqrt(2);
dst.at<double>(j + 100, i) = (gray_src.at<double>(j * 2, i) - gray_src.at<double>(j * 2 + 1, i)) / sqrt(2);
}
}
imshow(dst_title, dst);
waitKey(0);
return 0;
}
首先把输入图像转换成灰度图像,然后初始化一个同样大小和类型的dst
将灰度图像的相邻两个列的像素的和除以根号2,放在dst的左边;相邻两个列的像素的差除以根号2,放在dst的右边。
比如(0,0)和(0,1)的和除以根号2,放在dst的(0,0);(0,2)和(0,3)的和除以根号2,放在dst的(0,1);依次类推
程序在运行到for循环那里就不运行了,错误列表里面也没有信息。
麻烦各位前辈帮忙看看是什么地方出了问题
#include <iostream>
#include <opencv2/opencv.hpp>
#include <math.h>
using namespace cv;
int main()
{
//初始化矩阵
Mat src, gray_src, dst;
src = imread("1.jpg");
//创建图像窗口
std::string src_title = "原图像";
std::string gray_title = "灰度图像";
std::string dst_title = "输出图像";
namedWindow(src_title, WINDOW_NORMAL);
namedWindow(gray_title, WINDOW_NORMAL);
namedWindow(dst_title, WINDOW_NORMAL);
////图像填充
//copyMakeBorder(src, src_add, 2,2,0,0, BORDER_REFLECT);
//int width = src_add.rows;
//int height = src_add.cols;
//读取原图像宽高并显示原图像
int width = src.rows;
int height = src.cols;
std::cout << "width: " << width << " height: " << height << std::endl;
imshow(src_title, src);
//将原图像转化为灰度图像
cvtColor(src, gray_src, COLOR_BGR2GRAY);
//创建一个输出图像矩阵,大小类型与原图像一致
dst.create(gray_src.size(), gray_src.type());
imshow(gray_title, gray_src);
//haar行变换
for (int i = 0; i < gray_src.cols; i++)
{
for (int j = 0; j < gray_src.rows; j++)
{
dst.at<double>(j, i) = (gray_src.at<double>(j * 2, i) + gray_src.at<double>(j * 2 + 1, i)) / sqrt(2);
dst.at<double>(j + 100, i) = (gray_src.at<double>(j * 2, i) - gray_src.at<double>(j * 2 + 1, i)) / sqrt(2);
}
}
imshow(dst_title, dst);
waitKey(0);
return 0;
}