Commit f58ec6d7 authored by Nguyeng Hoang Giang's avatar Nguyeng Hoang Giang

fix

parent 2314dcee
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import org.apache.commons.lang3.ArrayUtils;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.w3c.dom.ls.LSOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class Fleet_single_cam {
private String id;
......@@ -63,6 +55,7 @@ public class Fleet_single_cam {
if (resize_ratio != 0) {
Imgproc.resize(this.image, this.image, new Size(0, 0), resize_ratio, resize_ratio);
}
//save image if require
if (show) {
Imgcodecs.imwrite("cam_" + id + ".png", this.image);
......
import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import java.util.Arrays;
import java.util.Comparator;
......@@ -72,7 +73,7 @@ public class Fleet_single_side {
new Point(rect[3][0], rect[3][1])
);
//compute the perspective transform matrix and then apply it
//compute the perspective transform matrix and then wrap the image to new size
Mat M = Imgproc.getPerspectiveTransform(src, dst);
Mat warped = new Mat();
Imgproc.warpPerspective(this.image, warped, M, new Size(maxWidth, maxHeight));
......@@ -141,7 +142,7 @@ public class Fleet_single_side {
//map condition
for (int i = 0; i < num_x; i++) {
for (int j = 0; j < num_y; j++) {
if ((mat[i][j] >= (mean - 0.5 * std)) && (mat[i][j] <= (mean + 3.0 * std)) && (mat[i][j]>stride_h*stride_w/16)) {
if ((mat[i][j] >= (mean - 0.5 * std)) && (mat[i][j] <= (mean + 3.0 * std)) && (mat[i][j] > stride_h * stride_w / 16)) {
mat[i][j] = 1;
} else {
mat[i][j] = 0;
......@@ -203,46 +204,45 @@ public class Fleet_single_side {
int idx = 0;
//find index of topMost
for (int i=0;i<clockwise_pts.length;i++){
if (Arrays.equals(clockwise_pts[i], topMost)){
idx=i;
for (int i = 0; i < clockwise_pts.length; i++) {
if (Arrays.equals(clockwise_pts[i], topMost)) {
idx = i;
break;
}
}
//sort topMost is the first element
float[][] order_pts = new float[4][2];
if (idx!=0){
System.arraycopy(clockwise_pts, idx, order_pts, 0, clockwise_pts.length-idx);
System.arraycopy(clockwise_pts, 0, order_pts, clockwise_pts.length-idx, idx);
}else{
if (idx != 0) {
System.arraycopy(clockwise_pts, idx, order_pts, 0, clockwise_pts.length - idx);
System.arraycopy(clockwise_pts, 0, order_pts, clockwise_pts.length - idx, idx);
} else {
order_pts = clockwise_pts;
}
// topMost is top-left
if (Arrays.stream(leftMost).anyMatch(point -> {
return Arrays.equals(point, topMost);
})){
})) {
return order_pts;
}else{//topMost is top-right
float[] temp = order_pts[order_pts.length-1];
System.arraycopy(order_pts,0 , order_pts, 1, order_pts.length-1);
} else {//topMost is top-right
float[] temp = order_pts[order_pts.length - 1];
System.arraycopy(order_pts, 0, order_pts, 1, order_pts.length - 1);
order_pts[0] = temp;
return order_pts;
}
}
private float[][] sort_clockwise(float[][] pts){
private float[][] sort_clockwise(float[][] pts) {
float[][] points = pts.clone();
float sum_x = 0;
float sum_y = 0;
//cal sum x, sum y
for (int i=0;i<points.length;i++){
sum_x+=points[i][0];
sum_y+=points[i][1];
for (int i = 0; i < points.length; i++) {
sum_x += points[i][0];
sum_y += points[i][1];
}
final float centre_x = sum_x / points.length;
final float centre_y = sum_y / points.length;
......@@ -251,8 +251,8 @@ public class Fleet_single_side {
Arrays.sort(points, new Comparator<float[]>() {
@Override
public int compare(float[] floats1, float[] floats2) {
return Double.compare(Math.atan2(floats1[1]-centre_y, floats1[0]-centre_x)
, Math.atan2(floats2[1]-centre_y, floats2[0]-centre_x) );
return Double.compare(Math.atan2(floats1[1] - centre_y, floats1[0] - centre_x)
, Math.atan2(floats2[1] - centre_y, floats2[0] - centre_x));
}
});
......
import org.bytedeco.javacpp.Loader;
import org.bytedeco.opencv.opencv_java;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.imgcodecs.Imgcodecs;
import java.util.Arrays;
import java.util.List;
public class main {
public static void main(String[] args){
public static void main(String[] args) {
Loader.load(opencv_java.class);
//Khoi tạo 1 cam, nhận ảnh tĩnh vào
Fleet_single_cam cam = new Fleet_single_cam("a", "5b8ab6b219c9d6978fd827.jpg", 0.5, 5, 5, 4, false);
//create fleet cam
Fleet_single_cam cam = new Fleet_single_cam("a","5b8ab6b219c9d6978fd827.jpg", 0.5, 5, 5, 4,false);
//create side_loc
Point[] side_loc = new Point[4];
//create bottom side
//create front side, add 4 đỉnh của side front vào
cam.add_side("front", new float[][]{
new float[]{687, 8},
new float[]{1264, 54},
......@@ -30,6 +17,7 @@ public class main {
new float[]{672, 305}
});
//create mặt side, add 4 đỉnh của mặt side vào
cam.add_side("side", new float[][]{
new float[]{12, 132},
new float[]{687, 8},
......@@ -37,6 +25,7 @@ public class main {
new float[]{275, 497}
});
//create bottom side, add 4 đỉnh của side bottom vào
cam.add_side("bottom", new float[][]{
new float[]{672, 305},
new float[]{1027, 432},
......@@ -48,10 +37,10 @@ public class main {
//print matrix
int[][] matrix = cam.side.get("front").getIntArray();
for (int i=0;i<matrix.length;i++){
for (int i = 0; i < matrix.length; i++) {
for (int j=0; j<matrix[0].length;j++){
System.out.print(matrix[i][j]+" ");
for (int j = 0; j < matrix[0].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
......@@ -59,10 +48,10 @@ public class main {
System.out.println();
int[][] matrix2 = cam.side.get("side").getIntArray();
for (int i=0;i<matrix2.length;i++){
for (int i = 0; i < matrix2.length; i++) {
for (int j=0; j<matrix2[0].length;j++){
System.out.print(matrix2[i][j]+" ");
for (int j = 0; j < matrix2[0].length; j++) {
System.out.print(matrix2[i][j] + " ");
}
System.out.println();
}
......@@ -70,10 +59,10 @@ public class main {
System.out.println();
int[][] matrix3 = cam.side.get("bottom").getIntArray();
for (int i=0;i<matrix2.length;i++){
for (int i = 0; i < matrix2.length; i++) {
for (int j=0; j<matrix3[0].length;j++){
System.out.print(matrix3[i][j]+" ");
for (int j = 0; j < matrix3[0].length; j++) {
System.out.print(matrix3[i][j] + " ");
}
System.out.println();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment