Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
compile java online
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
import java.io.File; import opencv2_cookbook.OpenCVUtils; import org.bytedeco.javacpp.opencv_core; import static org.bytedeco.javacpp.opencv_core.*; import org.bytedeco.javacpp.opencv_core.Mat; import static org.bytedeco.javacpp.opencv_core.CvType; import org.bytedeco.javacpp.opencv_core.MatVector; import org.bytedeco.javacpp.opencv_core.Rect; import static org.bytedeco.javacpp.opencv_highgui.CV_LOAD_IMAGE_COLOR; import org.bytedeco.javacpp.opencv_imgproc; import static org.bytedeco.javacpp.opencv_imgproc.*; public class GrabCut { public static void main(String[] arg) { Mat image = OpenCVUtils.loadMatAndShowOrExit(new File("F:\\images\\set2.jpg"), CV_LOAD_IMAGE_COLOR); Rect rectangle = new Rect(0, 0 , 224 , 224); Mat result = new Mat(); int iterCount = 5; int mode = GC_INIT_WITH_RECT; Mat bgdModel = new Mat(); Mat fgdModel = new Mat(); grabCut(image, result, rectangle, bgdModel, fgdModel, iterCount, mode); threshold(result, result, GC_PR_FGD - 0.5 , GC_PR_FGD + 0.5, THRESH_BINARY); //OpenCVUtils.show(OpenCVUtils.toIplImage8U(result.asIplImage() , true), "Result foreground mask"); //------------------------------------------------------------------------------------------------ Mat src = new Mat(result); //Mat tmp = new Mat(); Mat alpha = new Mat(); Mat dst = new Mat(); //cvtColor(image, tmp, CV_BGR2GRAY); //threshold(tmp, alpha, 255, 255, THRESH_BINARY); threshold(src, alpha, 150, 255, THRESH_BINARY); MatVector mavVector = new MatVector(3); split(image , mavVector); MatVector rgba = new MatVector(4); rgba.put(0,mavVector.get(0)); rgba.put(1,mavVector.get(1)); rgba.put(2,mavVector.get(2)); rgba.put(3,alpha); merge(rgba, dst); OpenCVUtils.show(dst , "123"); //OpenCVUtils.show(OpenCVUtils.toIplImage8U(dst.asIplImage() , true), "Result foreground mask"); } }
[
+
]
Show input
edit mode
|
history