求教,在用OpenCV java接口调用GrabCut图像分割函数时出现错误
1个回答
展开全部
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;
public class ImageSegment {
public static void main(String[] args) {
System.loadLibrary("opencv_java244");
Mat image = null;
image = Highgui.imread("syh.jpg");
Rect rectangle = new Rect(25,25,image.cols()-64,image.rows()-64);
Mat result = new Mat();
Mat bgdModel = new Mat();
Mat fgdModel = new Mat();
Mat source = new Mat(1, 1, CvType.CV_8U, new Scalar(3));
Imgproc.grabCut(image, result, rectangle, bgdModel, fgdModel, 1, 0);
Core.compare(result, source,result, Core.CMP_EQ);
Mat foreground= new Mat(image.size(), CvType.CV_8UC1, new Scalar(0, 0, 0));
image.copyTo(foreground, result);
Highgui.imwrite("sucess1.jpg", foreground);
System.out.println("grabcut sucess!");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询