我尝试使用MSER算法进行文本检测。我使用以下代码:
<UserControl x:Class="ConfigTool.Controls.RawNotificationTabItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ct_ctrls="clr-namespace:ConfigTool.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<ct_ctrls:CTDataGrid x:Name="notificationsGrid" ItemsSource="{Binding}" GridLinesVisibility="Vertical" AlternatingRowBackground="#C3DDE5"
AutoGenerateColumns="False" CanUserAddRows="True" IsReadOnly="False"
SelectionUnit="FullRow" SelectionMode="Extended" BorderThickness="3" CellEditEnding="CellEditingEnds" RowStyle="{StaticResource NotificationDataGridRow}">
<DataGrid.Resources>
<Style x:Key="wordWrapStyleView" TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
<Style x:Key="wordWrapStyleEdit" TargetType="{x:Type TextBox}">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Tag">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name="test" DataContext="{Binding}" ItemsSource="{Binding Path=Tags}"
Value="{Binding Path=Notification.TagName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append="False"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Nid" Binding="{Binding Mode=TwoWay, Path=Notification.Nid}"/>
<DataGridCheckBoxColumn Header="Active" Binding="{Binding Mode=TwoWay, Path=Notification.IsActive, Converter={StaticResource StringBoolConverter}}" IsThreeState="False"/>
<DataGridTextColumn Header="Type" Binding="{Binding Mode=TwoWay, Path=Notification.Type}"/>
<DataGridTextColumn Header="Limit" Binding="{Binding Mode=TwoWay, Path=Notification.Limit}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<AdornedElementPlaceholder x:Name="Limit"/>
<TextBlock Text="{Binding [0].ErrorContent}" Background="Red"/>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</DataGridTextColumn>
<DataGridTemplateColumn Header="Operator">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ComboBox x:Name="notificationOp" DataContext="{Binding}" ItemsSource="{Binding Path=Operations}"
Text="{Binding Path=Notification.Op}" IsEditable="False" VerticalAlignment="Top"
SelectedItem="{Binding Path=Notification.Op, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
</ComboBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Text" Binding="{Binding Mode=TwoWay, Path=Notification.Text}"/>
<DataGridTextColumn Header="Deadband" Binding="{Binding Mode=TwoWay, Path=Notification.Deadband}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Delay" ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}"
Binding="{Binding Mode=TwoWay, Path=Notification.Delay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Stretch"/>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Expand" ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}"
Binding="{Binding Mode=TwoWay, Path=Notification.Expand, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Stretch"/>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="SampleCount" ElementStyle="{StaticResource ResourceKey=textBlockErrStyle}"
Binding="{Binding Mode=TwoWay, Path=Notification.SampleCount, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Stretch"/>
<Setter Property="TextBlock.TextAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTemplateColumn Header="DetailTemplate">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name="test" DataContext="{Binding}" ItemsSource="{Binding Path=DetailTemplates}"
Value="{Binding Path=Notification.DetailTemplate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append="False"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="DetailParams" Width="300" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name="test" DataContext="{Binding}" ItemsSource="{Binding Path=Tags}"
Value="{Binding Path=Notification.DetailParamsString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append="True"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="unassigned"
Binding="{Binding Mode=OneWay, Path=Notification.Unassigned, ValidatesOnDataErrors=False, NotifyOnValidationError=False}"
ElementStyle="{StaticResource ResourceKey=textBlockUnassignedStyle}"/>
<DataGridTemplateColumn x:Name="EditNotificationsColumn" Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<Button x:Name="btnNotificationDelete" Click="BtnNotificationDelete_Click" Height="15" Width="15" Margin="2">
<Image Source="../Resources/delete.png"></Image>
</Button>
</WrapPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</ct_ctrls:CTDataGrid>
</Grid>
但是我得到非常有趣的结果。 MSER无法检测图像上的所有文本。
我在做什么错了?
答案 0 :(得分:1)
OpenCV文本模块包含几种用于文本检测的方法。对于您的示例,最简单的方法是ERFilterNM-python example。 png屏幕检测结果见: 参数:
er1 = cv.text.createERFilterNM1(erc1,6,0.00005f,0.08f,0.2f,true,0.1f)
er2 = cv.text.createERFilterNM2(erc1,0.15)