Select 来自 OpenCV.Point 数组的整数数组

Select integer array from OpenCV.Point array

我正在尝试 select 数组中的整数 OpenCvSharp.Point。

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

这一行失败,编译器告诉我 "Error overloading because there's no [Select] for these types of arguments"。

正确的做法是什么?

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

结束命名空间

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

.Select(i => i + 48)

(注意 => 不是 >=)并且 VB 等价物是这样的:

.Select(Function(i) i + 48)

这是否解决了您的问题?

编辑:

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