Вот код на C++. Поскольку используются в основном OpenCV функции, вы можете быть в состоянии порта это сделать андроида CV легко:
int main()
{
// loading your image. you dont need theses parts
cv::Mat input = cv::imread("../inputData/FormularLineDetection.png");
// convert to grayscale: you will do something similar:
cv::Mat gray;
cv::cvtColor(input, gray, CV_BGR2GRAY);
// computation of binary thresholding so that dark areas of the image will bevcome "foreground pixel".
// If your image have bright features you'll have to choose different parameters.
// If you want to detect contour lines instead you'll compute gradient magnitude first.
cv::Mat mask;
cv::threshold(gray, mask, 0, 255, CV_THRESH_BINARY_INV | CV_THRESH_OTSU);
std::vector<cv::Vec4i> lines;
//cv::HoughLinesP(mask, lines, 1, CV_PI/180.0, 50, 50, 10);
// I've changed the min-Size of a line to 1/3 of the images width. Maybe you'll have to adjust that parameter to your needs!
cv::HoughLinesP(mask, lines, 1, CV_PI/180.0, 50, input.cols/3, 10);
// draw the lines to visualize: you might not do this at all
for(size_t i = 0; i < lines.size(); i++)
{
cv::Vec4i l = lines[i];
cv::line(input, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0,0,255), 3, CV_AA);
}
// display and save to disk
cv::imshow("mask", mask); // you might not want to display the image here.
cv::imshow("output",input);
cv::imwrite("../outputData/FormularLineDetection.png", input);
cv::waitKey(0);
return 0;
}
с входом я получаю этот выход:
, как вы можете видеть, ваш желаемый линии, но, кроме того, обнаруживается большая толстая «линия». Вы можете попытаться обнаружить такие структуры и отфильтровать их!
Возможно, ваша линия слишком толстая, поэтому в вашей толстой линии вы найдете много линий шириной 1 ширину. отправьте свое исходное изображение и, если возможно, изображение со всеми обнаруженными линиями. – Micka
minLineSize следует измерять на расстоянии в пикселях (вероятно, евклидовом или приближенном эвклидовом) – Micka
@Micka Изображение сейчас в вопросе –