-
大小: 78.97MB文件类型: .zip金币: 2下载: 1 次发布日期: 2022-12-18
- 语言: 其他
- 标签: learnopencv-
资源简介
learnopencv-master
代码片段和文件信息
//
// alphaBlend.cpp
//
//
// Created by Sunita Nayak on 3/14/17.
//
//
#include
using namespace cv;
using namespace std;
// Alpha blending using multiply and add functions
Mat& blend(Mat& alpha Mat& foreground Mat& background Mat& outImage)
{
Mat fore back;
multiply(alpha foreground fore);
multiply(Scalar::all(1.0)-alpha background back);
add(fore back outImage);
return outImage;
}
// Alpha Blending using direct pointer access
Mat& alphaBlendDirectAccess(Mat& alpha Mat& foreground Mat& background Mat& outImage)
{
int numberOfPixels = foreground.rows * foreground.cols * foreground.channels();
float* fptr = reinterpret_cast(foreground.data);
float* bptr = reinterpret_cast(background.data);
float* aptr = reinterpret_cast(alpha.data);
float* outImagePtr = reinterpret_cast(outImage.data);
int ij;
for ( j = 0; j < numberOfPixels; ++j outImagePtr++ fptr++ aptr++ bptr++)
{
*outImagePtr = (*fptr)*(*aptr) + (*bptr)*(1 - *aptr);
}
return outImage;
}
int main(int argc char** argv)
{
// Read in the png foreground asset file that contains both rgb and alpha information
Mat foreGroundImage = imread(“foreGroundAssetLarge.png“ -1);
Mat bgra[4];
split(foreGroundImage bgra);//split png foreground
// Save the foregroung RGB content into a single Mat
vector foregroundChannels;
foregroundChannels.push_back(bgra[0]);
foregroundChannels.push_back(bgra[1]);
foregroundChannels.push_back(bgra[2]);
Mat foreground = Mat::zeros(foreGroundImage.size() CV_8UC3);
merge(foregroundChannels foreground);
// Save the alpha information into a single Mat
vector alphaChannels;
alphaChannels.push_back(bgra[3]);
alphaChannels.push_back(bgra[3]);
alphaChannels.push_back(bgra[3]);
Mat alpha = Mat::zeros(foreGroundImage.size() CV_8UC3);
merge(alphaChannels alpha);
// Read background image
Mat background = imread(“backGroundLarge.jpg“);
// Convert Mat to float data type
foreground.convertTo(foreground CV_32FC3);
background.convertTo(background CV_32FC3);
alpha.convertTo(alpha CV_32FC3 1.0/255); // keeps the alpha values betwen 0 and 1
// Number of iterations to average the performane over
int numOfIterations = 1; //1000;
// Alpha blending using functions multiply and add
Mat outImage= Mat::zeros(foreground.size() foreground.type());
double t = (double)getTickCount();
for (int i=0; i outImage = blend(alpha foreground background outImage);
}
t = ((double)getTickCount() - t)/getTickFrequency();
cout << “Time for alpha blending using multiply & add function : “ << t*1000/numOfIterations << “ milliseconds“ << endl;
// Alpha blending using direct Mat access with for loop
outImage = Mat::zeros(foreground.size()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-06-20 16:20 learnopencv-master\
文件 10 2018-06-20 16:20 learnopencv-master\.gitignore
目录 0 2018-06-20 16:20 learnopencv-master\AlphaBlending\
文件 254 2018-06-20 16:20 learnopencv-master\AlphaBlending\README.md
文件 3459 2018-06-20 16:20 learnopencv-master\AlphaBlending\alphaBlend.cpp
文件 862 2018-06-20 16:20 learnopencv-master\AlphaBlending\alphaBlend.py
文件 495797 2018-06-20 16:20 learnopencv-master\AlphaBlending\backGround.jpg
文件 735761 2018-06-20 16:20 learnopencv-master\AlphaBlending\backGroundLarge.jpg
文件 1718187 2018-06-20 16:20 learnopencv-master\AlphaBlending\foreGroundAsset.png
文件 6353004 2018-06-20 16:20 learnopencv-master\AlphaBlending\foreGroundAssetLarge.png
目录 0 2018-06-20 16:20 learnopencv-master\BlobDetector\
文件 251 2018-06-20 16:20 learnopencv-master\BlobDetector\README.md
文件 1555 2018-06-20 16:20 learnopencv-master\BlobDetector\blob.cpp
文件 16934 2018-06-20 16:20 learnopencv-master\BlobDetector\blob.jpg
文件 1202 2018-06-20 16:20 learnopencv-master\BlobDetector\blob.py
目录 0 2018-06-20 16:20 learnopencv-master\ColorSpaces\
文件 239 2018-06-20 16:20 learnopencv-master\ColorSpaces\README.md
文件 3281 2018-06-20 16:20 learnopencv-master\ColorSpaces\dataAnalysis.py
目录 0 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\
文件 28785 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub00.jpg
文件 20412 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub01.jpg
文件 24052 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub02.jpg
文件 24097 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub03.jpg
文件 19618 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub04.jpg
文件 27214 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub05.jpg
文件 40374 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub06.jpg
文件 33204 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub07.jpg
文件 30914 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub08.jpg
文件 29708 2018-06-20 16:20 learnopencv-master\ColorSpaces\images\rub09.jpg
文件 3577 2018-06-20 16:20 learnopencv-master\ColorSpaces\interactiveColorDetect.cpp
文件 2663 2018-06-20 16:20 learnopencv-master\ColorSpaces\interactiveColorDetect.py
............此处省略2362个文件信息
评论
共有 条评论