1
を無視して、私はイメージを持っている:のJava - OpenCVのは、余分な輪郭
私は本はそれ自体であるので、それをトリミングしたいです。
私はOpenCVを使用して画像の操作を試みています。私がそれらを描くと、それはこのように見えます。画像の右側に余分な輪郭を無視するにはどうすればよいですか?私は標準偏差の外れ値を使って試しています。今は、直方体内のすべての点を取り、それを後の処理のためにarraylistに追加します。私はポイントのための全体的なarraylistを持っています、そして2より多くので、統計分析を計算するとき、ポイントは最小から最大まで並べることができます。これは、それが今のように見えるものである
:
import java.awt.Point;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Rect;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class imtest {
public static void main(String args[]) throws IOException{
String filename="C:/image.png";
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat torect=new Mat();
Mat torect1=Imgcodecs.imread(filename,0);
Imgproc.Canny(torect1, torect, 10, 100);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(torect.clone(), contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
ArrayList<Point> outlie=new ArrayList<Point>();
ArrayList<Integer> ylist=new ArrayList<Integer>();
ArrayList<Integer> xlist=new ArrayList<Integer>();
MatOfPoint2f approxCurve = new MatOfPoint2f();
//For each contour found
for (int i=0; i<contours.size(); i++)
{
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(i).toArray());
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint(approxCurve.toArray());
// Get bounding rect of contour
Rect rect = Imgproc.boundingRect(points);
int xoffset=rect.x;
int yoffset=rect.y;
for (int y = 0; y < rect.height; y++) {
for (int x = 0; x < rect.width; x++) {
if (yoffset>1 & xoffset>1)
{
outlie.add(new Point(xoffset+x,yoffset+y));
ylist.add(yoffset+y);
xlist.add(xoffset+x);
}
}
}
}
}
}