【问题标题】:Select integer array from OpenCV.Point array从 OpenCV.Point 数组中选择整数数组
【发布时间】:2018-09-19 10:36:33
【问题描述】:

我正在尝试从 OpenCvSharp.Point 数组中选择整数。

Dim hull() As Integer = Cv2.ConvexHullIndices(origPoints.Skip(48)).Select(i >= i + 48)

此行失败,编译器告诉我“错误重载,因为这些类型的参数没有 [Select]”。

这样做的正确方法是什么?

origPoints 声明如下:

Dim origPoints() As OpenCvSharp.Point 

ConverHullIndices 声明如下:

Public Shared Function ConvexHullIndices(points As IEnumerable(Of Point), Optional clockwise As Boolean = False) As Integer()

OpenCvSharp.Point 声明如下:

#Region "Assembly OpenCvSharp, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=6adad1e807fea099"
' D:\Dev\Projects\faceshift\faceshift\packages\OpenCvSharp3- 
AnyCPU.3.4.1.20180830\lib\net46\OpenCvSharp.dll
#End Region

Imports System

Namespace OpenCvSharp
'
Public Structure Point
    Implements IEquatable(Of Point)
    '
    Public Const SizeOf As Integer = 8
    '
    Public X As Integer
    '
    Public Y As Integer

    '
    ' Parameter:
    '   x:
    '
    '   y:
    Public Sub New(x As Integer, y As Integer)
    '
    ' Parameter:
    '   x:
    '
    '   y:
    Public Sub New(x As Double, y As Double)

    '
    ' Zusammenfassung:
    '     Calculates the dot product of two 2D vectors.
    '
    ' Parameter:
    '   p1:
    '
    '   p2:
    Public Shared Function DotProduct(p1 As Point, p2 As Point) As Double
    '
    ' Zusammenfassung:
    '     Returns the distance between the specified two points
    '
    ' Parameter:
    '   p1:
    '
    '   p2:
    Public Shared Function Distance(p1 As Point, p2 As Point) As Double
    '
    ' Zusammenfassung:
    '     Calculates the cross product of two 2D vectors.
    '
    ' Parameter:
    '   p1:
    '
    '   p2:
    Public Shared Function CrossProduct(p1 As Point, p2 As Point) As Double
    '
    ' Zusammenfassung:
    '     Calculates the dot product of two 2D vectors.
    '
    ' Parameter:
    '   p:
    Public Function DotProduct(p As Point) As Double
    '
    ' Zusammenfassung:
    '     Returns the distance between the specified two points
    '
    ' Parameter:
    '   p:
    Public Function DistanceTo(p As Point) As Double
    '
    ' Zusammenfassung:
    '     Converts this object to a human readable string.
    '
    ' Rückgabewerte:
    '     A string that represents this object.
    Public Overrides Function ToString() As String
    '
    ' Zusammenfassung:
    '     Returns a hash code for this object.
    '
    ' Rückgabewerte:
    '     An integer value that specifies a hash value for this object.
    Public Overrides Function GetHashCode() As Integer
    '
    ' Zusammenfassung:
    '     Specifies whether this object contains the same members as the specified Object.
    '
    ' Parameter:
    '   obj:
    '     The Object to test.
    '
    ' Rückgabewerte:
    '     This method returns true if obj is the same type as this object and has the same
    '     members as this object.
    Public Overrides Function Equals(obj As Object) As Boolean
    '
    ' Zusammenfassung:
    '     Calculates the cross product of two 2D vectors.
    '
    ' Parameter:
    '   p:
    Public Function CrossProduct(p As Point) As Double
    '
    ' Zusammenfassung:
    '     Specifies whether this object contains the same members as the specified Object.
    '
    ' Parameter:
    '   obj:
    '     The Object to test.
    '
    ' Rückgabewerte:
    '     This method returns true if obj is the same type as this object and has the same
    '     members as this object.
    Public Function Equals(obj As Point) As Boolean

    '
    ' Zusammenfassung:
    '     Unary plus operator
    '
    ' Parameter:
    '   pt:
    Public Shared Operator +(pt As Point) As Point
    '
    ' Zusammenfassung:
    '     Shifts point by a certain offset
    '
    ' Parameter:
    '   p1:
    '
    '   p2:
    Public Shared Operator +(p1 As Point, p2 As Point) As Point
    '
    ' Zusammenfassung:
    '     Unary minus operator
    '
    ' Parameter:
    '   pt:
    Public Shared Operator -(pt As Point) As Point
    '
    ' Zusammenfassung:
    '     Shifts point by a certain offset
    '
    ' Parameter:
    '   p1:
    '
    '   p2:
    Public Shared Operator -(p1 As Point, p2 As Point) As Point
    '
    ' Zusammenfassung:
    '     Shifts point by a certain offset
    '
    ' Parameter:
    '   pt:
    '
    '   scale:
    Public Shared Operator *(pt As Point, scale As Double) As Point
    '
    ' Zusammenfassung:
    '     Compares two Point objects. The result specifies whether the values of the X
    '     and Y properties of the two Point objects are equal.
    '
    ' Parameter:
    '   lhs:
    '     A Point to compare.
    '
    '   rhs:
    '     A Point to compare.
    '
    ' Rückgabewerte:
    '     This operator returns true if the X and Y values of left and right are equal;
    '     otherwise, false.
    Public Shared Operator =(lhs As Point, rhs As Point) As Boolean
    '
    ' Zusammenfassung:
    '     Compares two Point objects. The result specifies whether the values of the X
    '     or Y properties of the two Point objects are unequal.
    '
    ' Parameter:
    '   lhs:
    '     A Point to compare.
    '
    '   rhs:
    '     A Point to compare.
    '
    ' Rückgabewerte:
    '     This operator returns true if the values of either the X properties or the Y
    '     properties of left and right differ; otherwise, false.
    Public Shared Operator <>(lhs As Point, rhs As Point) As Boolean
    Public Shared Widening Operator CType(vec As Vec2i) As Point
    Public Shared Widening Operator CType(point As Point) As Vec2i
End Structure

结束命名空间

【问题讨论】:

    标签: vb.net linq select opencvsharp


    【解决方案1】:

    我认为您错误地编写了 C# lambda 而不是 VB lambda。这在 C# 中是有效的:

    .Select(i => i + 48)
    

    (注意 =&gt; 不是 &gt;=)和 VB 等价物是这样的:

    .Select(Function(i) i + 48)
    

    这能解决你的问题吗?

    编辑:

    此外,Select 方法将返回一个 IEnumerable(Of T),因此,如果您想要一个数组,则需要附加对 ToArray 的调用。

    【讨论】:

    • 谢谢你,也谢谢你给我上不同运算符的课!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多