我有带有 Alpha 通道的视频,我尝试将其放置在另一个视频上,如下所示:
public static void overlayImage(Mat background, Mat foreground, Mat output, Point location) {
background.copyTo(output);
for (int y = (int) Math.max(location.y, 0); y < background.rows(); ++y) {
int fY = (int) (y - location.y);
if (fY >= foreground.rows()) {
break;
}
for (int x = (int) Math.max(location.x, 0); x < background.cols(); ++x) {
int fX = (int) (x - location.x);
if (fX >= foreground.cols()) {
break;
}
double opacity;
double[] finalPixelValue = new double[4];
opacity = foreground.get(fY, fX)[3];
finalPixelValue[0] …Run Code Online (Sandbox Code Playgroud)