您的位置:首页 > 其它

基于FPGA的Alpha半透明图像叠加算法实现

2016-07-22 09:22 381 查看
#include<opencv2\opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
Mat dealImg(Mat &img);

int main() {
Mat img = imread("E://ͼƬ//1.png");
if (img.empty()) {
return -1;
}
Mat result;

result = dealImg(img);

waitKey(0);
destroyAllWindows;
return 0;
}

Mat dealImg(Mat & img){
Mat temp;
Mat img1 = imread("E://ͼƬ//5.jpg");
if (img1.empty()) {
return Mat();
}
img.convertTo(temp, CV_32F);

Mat img2(temp.size(), img1.type());
resize(img1, img2, temp.size());

img2.convertTo(img2, CV_32F);
Mat result = temp.clone();
float alpha = 0.35;   //调整透光

for (int i = 0; i < temp.rows; i++) {
float *ptr_result = result.ptr<float>(i);
float *ptr_temp = temp.ptr<float>(i);
float *ptr_img1 = img2.ptr<float>(i);
for (int j = 0; j < temp.cols; j++) {
ptr_result[j * 3 + 0] = (1 - alpha)*ptr_img1[j * 3 + 0] + alpha*ptr_temp[j * 3 + 0];
ptr_result[j * 3 + 1] = (1 - alpha)*ptr_img1[j * 3 + 1] + alpha*ptr_temp[j * 3 + 1];
ptr_result[j * 3 + 2] = (1 - alpha)*ptr_img1[j * 3 + 2] + alpha*ptr_temp[j * 3 + 2];
}
}
result.convertTo(result, CV_8U);
imshow("result", result);
return result;
}






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: