我正在处理带有字典定义的图像,如下所示: 我想摆脱相邻条目(顶部和机器人)中的那些小元素,如果它们触摸图像的上部或机器人边界并且不超过20个像素(不包括任何接触顶部或机器人的实际字母) ,如此图像所示(红色):
我尝试这样做的方式是:
1.以灰度加载图像
2.使用 public class DbInitializer
{
public static void Seed(IApplicationBuilder applicationBuilder)
{
AppDbContext context = applicationBuilder.ApplicationServices.GetRequiredService<AppDbContext>();
if (!context.Categories.Any())
{
context.AddRange(
new Category { CategoryName = "First Pie", Description="Descriptionslqdfq vdfhsqdqsdhfs qsdhf" },
new Category { CategoryName = "Cheese Cackes", Description = "Descriptionslqdfq vdfhsqdqsdhfs qsdhf" },
new Category { CategoryName = "Saesonal Pie", Description = "Descriptionslqdfq vdfhsqdqsdhfs qsdhf" });
}
if (!context.Pies.Any())
{
context.AddRange(new Pie { Name = "Apple Pie", ShortDescrition = "short description", LongDescription = "Long description", AllegryInformation = "sflqjq", ImageUrl = "#", IsPieOfTheWeek = true, InStock = true, Price = 15.65M },
new Pie { Name = "Apple Pie", ShortDescrition = "short description", LongDescription = "Long description", AllegryInformation = "sflqjq", ImageUrl = "#", IsPieOfTheWeek = true, InStock = true, Price = 15.65M },
new Pie { Name = "Apple Pie", ShortDescrition = "short description", LongDescription = "Long description", AllegryInformation = "sflqjq", ImageUrl = "#", IsPieOfTheWeek = true, InStock = true, Price = 15.65M },
new Pie { Name = "Apple Pie", ShortDescrition = "short description", LongDescription = "Long description", AllegryInformation = "sflqjq", ImageUrl = "#", IsPieOfTheWeek = true, InStock = true, Price = 15.65M },
new Pie { Name = "Apple Pie", ShortDescrition = "short description", LongDescription = "Long description", AllegryInformation = "sflqjq", ImageUrl = "#", IsPieOfTheWeek = true, InStock = true, Price = 15.65M });
}
context.SaveChanges();
}
}
获取图像的轮廓
3.找到从x = 0开始但结尾不超过x = 20的轮廓
4.找到从高度-1开始到高度为21的轮廓
5.用白色绘制这些轮廓
问题是cv2.findContours
返回一组坐标数组的数组。虽然我能够删除某些坐标对,但我在这里应用它很困难。
我尝试了很多方法,目前我坚持这个:
cv2.findContours
答案 0 :(得分:1)
我认为没有必要在这里使用findContours
。
在您的情况下,我要做的是简单地迭代图像边框上的像素,并使用增长区域算法删除那些触摸边框的组件。更详细: