Seam Carving智能缩放算法的第一步就是图像能量的计算。
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include"opencv2/highgui/highgui.hpp"
#include<stdio.h>
#include<string>
#include<stdint.h>
using namespace std;
using namespace cv;
void SeamCarvercomputeFullEnergy(Mat&image,Mat &energy) {
//确保能量矩阵与图像匹配
energy.create(image.rows, image.cols, CV_32S);
//由第2行开始计算
for (int i = 1; i < image.rows - 1; ++i) {
uchar* prev = image.ptr<uchar>(i - 1); //Pointer to previous row
uchar* curr = image.ptr<uchar>(i); //Pointer to current row
uchar* next = image.ptr<uchar>(i + 1); //Pointer to next row
for (int j = 1; j < image.cols - 1; ++j) {
int val = 0;
//Energy along the x-axis
val += (prev[3 * j] - next[3 * j]) * (prev[3 * j] - next[3 * j]);
val += (prev[3 * j + 1] - next[3 * j + 1]) * (prev[3 * j + 1] - next[3 * j + 1]);
val += (prev[3 * j + 2] - next[3 * j + 2]) * (prev[