// Path: desktop/src/main/java/com/cv4j/core/datamodel/ByteProcessor.java
// public class ByteProcessor implements ImageProcessor {
//     private int width;
//     private int height;
// 
//     private byte[] GRAY;
//     private int[] hist;
//     private ImageData image;
// 
//     public ByteProcessor(int width, int height) {
//         this.width = width;
//         this.height = height;
//         this.GRAY = new byte[width*height];
//     }
//     
//     public ByteProcessor(byte[] data, int width, int height) {
//         this.width = width;
//         this.height = height;
//         this.GRAY = data;
//         // setup hist
//         hist = new int[256];
//         for(int i=0; i<data.length; i++) {
//             hist[data[i]&0xff]++;
//         }
//     }
// 
//     protected void setCallBack(ImageData data) {
//         this.image = data;
//     }
// 
//     @Override
//     public int getChannels() {
//         return 1;
//     }
// 
//     public void getPixel(int row, int col, byte[] rgb) {
//         int index = row*width + col;
//         if(rgb != null && rgb.length == 1) {
//             rgb[0] = GRAY[index];
//         }
//     }
// 
//     public byte[] getGray() {
//         return GRAY;
//     }
// 
//     public void putGray(byte[] gray) {
//         System.arraycopy(gray, 0, GRAY, 0, gray.length);
//     }
// 
//     public int[] histogram() {
//         return new int[0];
//     }
// 
//     public int[] getPixels() {
//         int size = width * height;
//         int[] pixels = new int[size];
//         for (int i=0; i < size; i++)
//             pixels[i] = 0xff000000 | ((GRAY[i]&0xff)<<16) | ((GRAY[i]&0xff)<<8) | GRAY[i]&0xff;
//         return pixels;
//     }
// 
//     @Override
//     public float[] toFloat(int index) {
//         float[] data = new float[GRAY.length];
//         for(int i=0; i<data.length; i++)
//             data[i] = GRAY[i]&0xff;
//         return data;
//     }
// 
//     @Override
//     public int[] toInt(int index) {
//         int[] data = new int[GRAY.length];
//         for(int i=0; i<data.length; i++)
//             data[i] = GRAY[i]&0xff;
//         return data;
//     }
// 
//     @Override
//     public byte[] toByte(int index) {
//         return GRAY;
//     }
// 
// 	@Override
// 	public int getWidth() {
// 		return width;
// 	}
// 
// 	@Override
// 	public int getHeight() {
// 		return height;
// 	}
// 
// 	@Override
// 	public ImageData getImage() {
// 
// 		return image;
// 	}
// 
// }
// 
// Path: desktop/src/main/java/com/cv4j/core/datamodel/Line.java
// public class Line {
//     public int x1 = 0;
//     public int y1 = 0;
//     public int x2 = 0;
//     public int y2 = 0;
// 
//     public Line(int x1, int y1, int x2, int y2) {
//         this.x1 = x1;
//         this.y1 = y1;
//         this.x2 = x2;
//         this.y2 = y2;
//     }
// 
//     public Line() {}
// 
//     public double getSlope() {
//         double dy = y2 - y1;
//         double dx = x2 - x1;
//         if(dx == 0) {
//             return Double.NaN;
//         }
//         return (dy/dx);
//     }
// 
//     public Point getPoint1() {
//         return new Point(x1, y1);
//     }
// 
//     public Point getPoint2() {
//         return new Point(x2, y2);
//     }
// 
// }


import com.cv4j.core.datamodel.ByteProcessor;
import com.cv4j.core.datamodel.Line;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * Copyright (c) 2017-present, CV4J Contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cv4j.core.binary;



public class HoughLinesP {
	private double[] coslut;
	private double[] sinlut;
	private int accSize;
	private int width;
	private int height;
	private int accThreshold;

	public HoughLinesP() {
		setupCosLUT();
		setupSinLUT();
	}

	/**
	 * 1. 初始化霍夫变换空间
	 * 2. 将图像的2D空间转换到霍夫空间,每个像素坐标都要转换到霍夫极坐标的对应强度值
	 * 3. 找出霍夫极坐标空间的最大强度值
	 * 4. 根据最大强度值归一化,范围为0 ~ 255
	 * 5. 根据输入前accSize值,画出前accSize个信号最强的直线
	 *
	 * @return
	 */
// Path: desktop/src/main/java/com/cv4j/core/datamodel/ByteProcessor.java
// public class ByteProcessor implements ImageProcessor {
//     private int width;
//     private int height;
// 
//     private byte[] GRAY;
//     private int[] hist;
//     private ImageData image;
// 
//     public ByteProcessor(int width, int height) {
//         this.width = width;
//         this.height = height;
//         this.GRAY = new byte[width*height];
//     }
//     
//     public ByteProcessor(byte[] data, int width, int height) {
//         this.width = width;
//         this.height = height;
//         this.GRAY = data;
//         // setup hist
//         hist = new int[256];
//         for(int i=0; i<data.length; i++) {
//             hist[data[i]&0xff]++;
//         }
//     }
// 
//     protected void setCallBack(ImageData data) {
//         this.image = data;
//     }
// 
//     @Override
//     public int getChannels() {
//         return 1;
//     }
// 
//     public void getPixel(int row, int col, byte[] rgb) {
//         int index = row*width + col;
//         if(rgb != null && rgb.length == 1) {
//             rgb[0] = GRAY[index];
//         }
//     }
// 
//     public byte[] getGray() {
//         return GRAY;
//     }
// 
//     public void putGray(byte[] gray) {
//         System.arraycopy(gray, 0, GRAY, 0, gray.length);
//     }
// 
//     public int[] histogram() {
//         return new int[0];
//     }
// 
//     public int[] getPixels() {
//         int size = width * height;
//         int[] pixels = new int[size];
//         for (int i=0; i < size; i++)
//             pixels[i] = 0xff000000 | ((GRAY[i]&0xff)<<16) | ((GRAY[i]&0xff)<<8) | GRAY[i]&0xff;
//         return pixels;
//     }
// 
//     @Override
//     public float[] toFloat(int index) {
//         float[] data = new float[GRAY.length];
//         for(int i=0; i<data.length; i++)
//             data[i] = GRAY[i]&0xff;
//         return data;
//     }
// 
//     @Override
//     public int[] toInt(int index) {
//         int[] data = new int[GRAY.length];
//         for(int i=0; i<data.length; i++)
//             data[i] = GRAY[i]&0xff;
//         return data;
//     }
// 
//     @Override
//     public byte[] toByte(int index) {
//         return GRAY;
//     }
// 
// 	@Override
// 	public int getWidth() {
// 		return width;
// 	}
// 
// 	@Override
// 	public int getHeight() {
// 		return height;
// 	}
// 
// 	@Override
// 	public ImageData getImage() {
// 
// 		return image;
// 	}
// 
// }
// 
// Path: desktop/src/main/java/com/cv4j/core/datamodel/Line.java
// public class Line {
//     public int x1 = 0;
//     public int y1 = 0;
//     public int x2 = 0;
//     public int y2 = 0;
// 
//     public Line(int x1, int y1, int x2, int y2) {
//         this.x1 = x1;
//         this.y1 = y1;
//         this.x2 = x2;
//         this.y2 = y2;
//     }
// 
//     public Line() {}
// 
//     public double getSlope() {
//         double dy = y2 - y1;
//         double dx = x2 - x1;
//         if(dx == 0) {
//             return Double.NaN;
//         }
//         return (dy/dx);
//     }
// 
//     public Point getPoint1() {
//         return new Point(x1, y1);
//     }
// 
//     public Point getPoint2() {
//         return new Point(x2, y2);
//     }
// 
// }


// Path: desktop/src/main/java/com/cv4j/core/binary/HoughLinesP.java
import com.cv4j.core.datamodel.ByteProcessor;
import com.cv4j.core.datamodel.Line;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Copyright (c) 2017-present, CV4J Contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cv4j.core.binary;



public class HoughLinesP {
	private double[] coslut;
	private double[] sinlut;
	private int accSize;
	private int width;
	private int height;
	private int accThreshold;

	public HoughLinesP() {
		setupCosLUT();
		setupSinLUT();
	}

	/**
	 * 1. 初始化霍夫变换空间
	 * 2. 将图像的2D空间转换到霍夫空间,每个像素坐标都要转换到霍夫极坐标的对应强度值
	 * 3. 找出霍夫极坐标空间的最大强度值
	 * 4. 根据最大强度值归一化,范围为0 ~ 255
	 * 5. 根据输入前accSize值,画出前accSize个信号最强的直线
	 *
	 * @return
	 */
	public void process(ByteProcessor binary, int accSize, int minGap, int minAcc, List<Line> lines) {