My mRgba object has dimensions 0X0 so it doesn't return any lines on the picture at all.I guess it is empty. What is the problem in the code? Is there a way to show lines just on the black background?
Here is the code
mat = new Mat();
edges = new Mat();
Size kernel = new Size(5, 5);
Mat gauss = new Mat();
Mat mRgba = new Mat(612,816, CvType.CV_8UC1);
Mat lines = new Mat(612,816, CvType.CV_8UC1);
binary_image = new Mat();
Utils.bitmapToMat(bitmap, mat);
Imgproc.GaussianBlur(mat, gauss, kernel, 10000, 10000);
Imgproc.Canny(gauss, edges, 50, 90);
Imgproc.threshold(edges, binary_image, 0, 255, Imgproc.THRESH_BINARY_INV);
int threshold = 50;
int minLineSize = 20;
int lineGap = 20;
Imgproc.HoughLinesP(binary_image, lines, 1, Math.PI / 180,threshold,minLineSize,lineGap);
for (int x = 0; x < lines.cols(); x++) {
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, new Scalar(255, 0, 0), 3);
}
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mRgba, bmp);
bitmap=bmp;
EDIT: The problem has been solved by removing GaussianBlur and threshold methods
mat = new Mat();
edges = new Mat();
Mat mRgba = new Mat(612,816, CvType.CV_8UC1);
Mat lines = new Mat();
Utils.bitmapToMat(bitmap, mat);
Imgproc.Canny(mat, edges, 50, 90);
int threshold = 50;
int minLineSize = 20;
int lineGap = 20;
Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180,threshold,minLineSize,lineGap);
for (int x = 0; x < lines.cols(); x++) {
double[] vec = lines.get(0, x);
double x1 = vec[0],
y1 = vec[1],
x2 = vec[2],
y2 = vec[3];
Point start = new Point(x1, y1);
Point end = new Point(x2, y2);
Core.line(mRgba, start, end, new Scalar(255, 0, 0), 3);
}
Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mRgba, bmp);
bitmap=bmp;
mRgba
when you are creating it, it should has the same size with the image that you are trying to find lines. lines
object, to see if you are able to find lines or
not. You can understand it by checking mRgba
.