110,473
社区成员
发帖
与我相关
我的任务
分享
Public Sub OpenCv_FanSe(ByRef src As Mat) '旋转图像
Dim grayImage As New Mat(), h, w As Integer, b, g, r As Byte
h = src.Rows : w = src.Cols
Dim channels As Integer = src.Channels()
'Cv2.CvtColor(src, grayImage, ColorConversionCodes.BGR2GRAY)
For i As Integer = 0 To h - 1
For j As Integer = 0 To w - 1
'If channels = 1 Then
' Dim gray As Byte = grayImage.Get(Of Byte)(i, j)
' grayImage.Set(Of Byte)(i, j, CByte(Byte.MaxValue - gray))
'ElseIf channels = 3 Then
'Dim b As Byte = img2.At(Of Vec3b)(i, j).Item0
'Dim g As Byte = img2.At(Of Vec3b)(i, j).Item1
'Dim r As Byte = img2.At(Of Vec3b)(i, j).Item2
b = src.At(Of Vec3b)(i, j).Item(0)
g = src.At(Of Vec3b)(i, j).Item(1)
r = src.At(Of Vec3b)(i, j).Item(2)
src.Set(Of Vec3b)(i, j, New Vec3b(CByte(255 - b), CByte(255 - g), CByte(255 - r)))
'End If
Next
Next
End Sub
请大家看看怎么改速度最快
Image<Gray, byte> image = new Image<Gray, byte>(bitmap);
Image<Gray, byte> image_threshold = image.CopyBlank();
CvInvoke.Threshold(image, image_threshold, 100, 255, ThresholdType.Binary);
DenseHistogram hist = new DenseHistogram(256, new RangeF(0f, 256f));
hist.Calculate(new Image<Gray, byte>[] { image_threshold }, false, null);
float[] datas = hist.GetBinValues();
float blackCount = datas[0];
float whiteCount = datas[255];
Console.WriteLine(blackCount + " " + whiteCount);