Last active
June 28, 2019 20:31
-
-
Save mbuczko/de50cb6a6a2d451a8227 to your computer and use it in GitHub Desktop.
clojure / OpenCV scale image preserving ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[org.opencv.core Mat Size CvType] '[org.opencv.highgui Highgui] '[org.opencv.imgproc Imgproc]) | |
(clojure.lang.RT/loadLibrary org.opencv.core.Core/NATIVE_LIBRARY_NAME) | |
(def angelina (Highgui/imread "resources/angelina.jpg")) | |
(def blurred (Mat. 960 1280 CvType/CV_8UC3)) | |
(Imgproc/GaussianBlur angelina blurred (Size. 5 5) 3 3) | |
(Highgui/imwrite "resources/images/blurred.png" blurred) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
how to install opencv jars: | |
lein localrepo install opencv-2410.jar opencv/opencv 2.4.10 | |
lein localrepo install opencv-native-2410.jar opencv/opencv-native 2.4.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[org.opencv.core Mat Size CvType] '[org.opencv.highgui Highgui] '[org.opencv.imgproc Imgproc]) | |
(clojure.lang.RT/loadLibrary org.opencv.core.Core/NATIVE_LIBRARY_NAME) | |
(def angelina (Highgui/imread "resources/angelina.jpg")) | |
(def resized (Mat. 100 512 CvType/CV_8UC3)) | |
(def ratio (/ 100 (.. angelina size width))) | |
(def dim (Size. 100 (* (.. angelina size height) ratio))) | |
(Imgproc/resize angelina resized dim 0 0 Imgproc/INTER_AREA) | |
(Highgui/imwrite "resources/resized.png" resized) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '[org.opencv.core Core Mat Size Rect CvType] '[org.opencv.highgui Highgui] '[org.opencv.imgproc Imgproc]) | |
(clojure.lang.RT/loadLibrary org.opencv.core.Core/NATIVE_LIBRARY_NAME) | |
(def watermark (Highgui/imread "resources/public/img/logo_watermark.png")) | |
(def angelina (Highgui/imread "resources/angelina.jpg")) | |
(def roi (Rect. (- (.width angelina) 180) (- (.height angelina) 30) (.width watermark) (.height watermark))) | |
(Core/addWeighted (.submat angelina roi) 0.8 watermark 0.2 1 (.submat angelina roi)) | |
(Highgui/imwrite "resources/watermarked.png" angelina) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment