opencv使用特征匹配查找单应性

时间:2016-12-01 13:15:33

标签: c++ opencv image-processing computer-vision homography

我在这里参考计算单应性。 http://docs.opencv.org/2.4/doc/tutorials/features2d/feature_homography/feature_homography.html

但是,即使它是参考代码也会出错。 min_dist值始终为0,因此good_matches的大小在代码中为0。

有什么问题,我们如何解决?

<?xml version="1.0" encoding="utf-8" ?>
<pages:BaseTabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:pages="clr-namespace:ABBI_XPlat_3.Pages;assembly=ABBI_XPlat_3"
         x:Class="ABBI_XPlat_3.Pages.DeviceListPage"
         Title="Discover devices"
         x:Name="DevicePage">
<pages:BaseTabbedPage.Resources>
  <ResourceDictionary>
     <DataTemplate x:Key="DeviceItemTemplate"> ... </DataTemplate>
  </ResourceDictionary>
</pages:BaseTabbedPage.Resources>
<pages:BaseTabbedPage.Children>
  <pages:BasePage Title="Scan for devices">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="Auto"></RowDefinition>
      </Grid.RowDefinitions>
      <StackLayout BackgroundColor="#FF6969" Padding="10" IsVisible="{Binding IsStateOn, Converter={StaticResource InverseBoolean}}">
        <Label Text="{Binding StateText}" FontSize="18" HorizontalTextAlignment="Center"></Label>
        </StackLayout>

      <ListView Grid.Row="1" ItemsSource="{Binding Devices}" SelectedItem="{Binding SelectedDevice, Mode=TwoWay}"
             IsPullToRefreshEnabled="True"
             RefreshCommand="{Binding RefreshCommand}"
             IsRefreshing="{Binding IsRefreshing, Mode=OneWay}"
             RowHeight="80"
             ItemTemplate="{StaticResource DeviceItemTemplate}">
      </ListView>

      <StackLayout Grid.Row="2" Orientation="Horizontal">
        <Button Text="Connect" Command="{Binding ConnectToSelectedCommand}" HorizontalOptions="FillAndExpand"/>
        <Button Text="Stop Scan" Command="{Binding StopScanCommand}" HorizontalOptions="End"/>
        <ActivityIndicator IsRunning="{Binding IsRefreshing}"
                         HeightRequest="24"
                         WidthRequest="24"
                         VerticalOptions="Center"
                         HorizontalOptions="End"/>
      </StackLayout>

    </Grid>
  </pages:BasePage>
  <pages:ServiceListPage Title="Services"/>
  <pages:OtherTabbedPage Title="Services"/>
</pages:BaseTabbedPage.Children>
</pages:BaseTabbedPage>

1 个答案:

答案 0 :(得分:0)

到目前为止,我无法在代码中看到任何错误的过程,但是你有3个Channel 8-Bit Image。尝试使用1通道8位图像,因为这是链接教程中图像的格式。因此,请尝试将cv::Mat img2(480, 640, CV_8UC3, cv::Scalar(0, 0, 0));更改为cv::Mat img2(480, 640, CV_8UC1, cv::Scalar(0, 0, 0));。如果这不适用于cam >> img,则必须在从相机中读取图片后尝试将图片转换为CV_8UC1