parent
89172c08a2
commit
c4c1e94088
5 changed files with 158 additions and 18 deletions
@ -0,0 +1,51 @@ |
|||||||
|
import org.opencv.core.*; |
||||||
|
import org.opencv.highgui.HighGui; |
||||||
|
import org.opencv.imgcodecs.Imgcodecs; |
||||||
|
|
||||||
|
import java.util.Locale; |
||||||
|
import java.util.Scanner; |
||||||
|
|
||||||
|
class AddingImagesRun{ |
||||||
|
public void run() { |
||||||
|
double alpha = 0.5; double beta; double input; |
||||||
|
|
||||||
|
Mat src1, src2, dst = new Mat(); |
||||||
|
|
||||||
|
System.out.println(" Simple Linear Blender "); |
||||||
|
System.out.println("-----------------------"); |
||||||
|
System.out.println("* Enter alpha [0.0-1.0]: "); |
||||||
|
Scanner scan = new Scanner( System.in ).useLocale(Locale.US); |
||||||
|
input = scan.nextDouble(); |
||||||
|
|
||||||
|
if( input >= 0.0 && input <= 1.0 ) |
||||||
|
alpha = input; |
||||||
|
|
||||||
|
//! [load]
|
||||||
|
src1 = Imgcodecs.imread("../../images/LinuxLogo.jpg"); |
||||||
|
src2 = Imgcodecs.imread("../../images/WindowsLogo.jpg"); |
||||||
|
//! [load]
|
||||||
|
|
||||||
|
if( src1.empty() == true ){ System.out.println("Error loading src1"); return;} |
||||||
|
if( src2.empty() == true ){ System.out.println("Error loading src2"); return;} |
||||||
|
|
||||||
|
//! [blend_images]
|
||||||
|
beta = ( 1.0 - alpha ); |
||||||
|
Core.addWeighted( src1, alpha, src2, beta, 0.0, dst); |
||||||
|
//! [blend_images]
|
||||||
|
|
||||||
|
//![display]
|
||||||
|
HighGui.imshow("Linear Blend", dst); |
||||||
|
HighGui.waitKey(0); |
||||||
|
//![display]
|
||||||
|
|
||||||
|
System.exit(0); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class AddingImages { |
||||||
|
public static void main(String[] args) { |
||||||
|
// Load the native library.
|
||||||
|
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
||||||
|
new AddingImagesRun().run(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
from __future__ import print_function |
||||||
|
import sys |
||||||
|
|
||||||
|
import cv2 |
||||||
|
|
||||||
|
alpha = 0.5 |
||||||
|
|
||||||
|
print(''' Simple Linear Blender |
||||||
|
----------------------- |
||||||
|
* Enter alpha [0.0-1.0]: ''') |
||||||
|
if sys.version_info >= (3, 0): # If Python 3.x |
||||||
|
input_alpha = float(input()) |
||||||
|
else: |
||||||
|
input_alpha = float(raw_input()) |
||||||
|
if 0 <= alpha <= 1: |
||||||
|
alpha = input_alpha |
||||||
|
## [load] |
||||||
|
src1 = cv2.imread('../../../../data/LinuxLogo.jpg') |
||||||
|
src2 = cv2.imread('../../../../data/WindowsLogo.jpg') |
||||||
|
## [load] |
||||||
|
if src1 is None: |
||||||
|
print ("Error loading src1") |
||||||
|
exit(-1) |
||||||
|
elif src2 is None: |
||||||
|
print ("Error loading src2") |
||||||
|
exit(-1) |
||||||
|
## [blend_images] |
||||||
|
beta = (1.0 - alpha) |
||||||
|
dst = cv2.addWeighted(src1, alpha, src2, beta, 0.0) |
||||||
|
## [blend_images] |
||||||
|
## [display] |
||||||
|
cv2.imshow('dst', dst) |
||||||
|
cv2.waitKey(0) |
||||||
|
## [display] |
||||||
|
cv2.destroyAllWindows() |
Loading…
Reference in new issue