opencv之图像混合(blending)

include
#include

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}

Mat src1,src2,dst;
double alpha=0.4,beta;
beta=1-alpha;
src1 = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

if(! src1.data )                              // Check for invalid input
{
cout <<  "Could not open or find the image" << std::endl ;
return -1;
}

CvCapture* capture = cvCreateFileCapture("rtsp://192.168.1.158/H264");
if(!capture)cvReleaseCapture( &capture );//  释放视频占用的内存空间
IplImage* frame;
frame = cvQueryFrame( capture );//获取视频的帧图片
if( !frame ) //如果没有图片的话停止播放
{
cvReleaseCapture( &capture );//  释放视频占用的内存空间
return 0;
}
src2=Mat(frame,cvRect(0,0,src1.rows,src1.cols));
addWeighted( src1, alpha, src2, beta, 0.0, dst);

namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", dst );                   // Show our image inside it.

waitKey(0);                                          // Wait for a keystroke in the window
cvReleaseCapture( &capture );//  释放视频占用的内存空间
cvDestroyWindow( "Example2" ); //销毁窗口  
return 0;
}

图像求和公式: dst = .alpha .cdot src1 + .beta .cdot src2 + .gamma

这里再说一个两路混音的公式:(并没有测试公式的效果)
C = A + B - (A * B >>  0x10 );
if (C >  32767) C =  32767;
else  if (C < - 32768) C = - 32768;

你可能感兴趣的:(eeworld)