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

来源:互联网 发布:黑客编程新手教学 编辑:程序博客网 时间:2024/05/16 17:05
#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;}



0 0
原创粉丝点击