Find Tables in Image using C#

爷,独闯天下 提交于 2019-12-23 05:22:13

问题


I am trying to write a function that will take an image and return me a list of images with only tables using EMGU.CV or Magick.Net or AForge.Net for example for the below image the function should return 2 images with the two tables in the image.

private static List<Image> FindTables(Image img)
{
    var masterImage = (Bitmap)img;
    var image = new Image<Gray, byte>(masterImage);
    var copyImg = new Image<Bgr, byte>(masterImage);
    List<Image> tables = new List<Images>
    //Find all tables and add to tables variable
    return tables;
}


回答1:


You can do that with connected components in Imagemagick. Filter out all regions that are small, which are text characters, leaving only the larger table outlines. Then get the bounding boxes for the tables and use those to crop the original image. Set the area-threshold so that the number of pixels in the lines of the table are larger than than the threshold and everything else is smaller than the threshold.

Input:

IFS=" "
OLDIFS=$IFS
IFS=$'\n'
bboxArr=(`convert image.png -alpha off -type bilevel \
-define connected-components:verbose=true \
-define connected-components:area-threshold=500 \
-connected-components 4 \
null: | grep "gray(0)" | awk '{print $2}'`)
num=${#bboxArr[*]}
IFS=$OLDIFS
for ((i=0; i<num; i++)); do
convert image.png -crop ${bboxArr[$i]} +repage image$i.png
done


Sorry, I do not know Magick.NET. But you can discuss that with the Magick.NET developer by asking at https://imagemagick.org/discourse-server/viewforum.php?f=27 or at https://github.com/dlemstra/Magick.NET



来源:https://stackoverflow.com/questions/54041326/find-tables-in-image-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!