https://github.com/scisharp/sharpcv
A Computer Vision library for C# and F# that combines OpenCV and NDArray together in .NET Standard.
https://github.com/scisharp/sharpcv
Last synced: about 1 year ago
JSON representation
A Computer Vision library for C# and F# that combines OpenCV and NDArray together in .NET Standard.
- Host: GitHub
- URL: https://github.com/scisharp/sharpcv
- Owner: SciSharp
- License: apache-2.0
- Created: 2019-12-26T02:49:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-06T00:56:31.000Z (over 2 years ago)
- Last Synced: 2025-06-11T19:53:14.366Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 1.63 MB
- Stars: 299
- Watchers: 18
- Forks: 56
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SharpCV
A image library combines [OpenCV](https://github.com/opencv/opencv) and [NumSharp](https://github.com/SciSharp/NumSharp.Lite) together. `SharpCV` returns `Mat` object with `NDArray` supported, which makes it easier to do data manipulation like slicing.
[](https://gitter.im/sci-sharp/community) [](https://www.nuget.org/packages/SharpCV)
### How to use
Install OpenCV prebuild binary
```powershell
PM> Install-Package SharpCV
PM> Install-Package OpenCvSharp4.runtime.win
```
Import SharpCV and OpenCV library
```csharp
using SharpCV;
using static SharpCV.Binding;
```
Interact with `NDArray`
```csharp
NDArray kernel = new float[,]
{
{ 0, -1, 0 },
{ -1, 5, -1 },
{ 0, -1, 0 }
};
var mat = new Mat(kernel);
Assert.AreEqual((3, 3), mat.shape);
Assert.AreEqual(kernel[0], mat.data[0]); // { 0, -1, 0 }
Assert.AreEqual(kernel[1], mat.data[1]); // { -1, 5, -1 }
Assert.AreEqual(kernel[2], mat.data[2]); // { 0, -1, 0 }
```
Pixel level access
```csharp
var img = cv2.imread(imgSolar, IMREAD_COLOR.IMREAD_GRAYSCALE);
byte p = img[8, 8];
Assert.AreEqual(18, p);
img = cv2.imread(imgSolar);
var (b, g, r) = img[8, 8];
Assert.AreEqual((32, 19, 11), (b, g, r));
```
Convert to black and white image
```csharp
var img = cv2.imread("solar.jpg");
var gray = cv2.cvtColor(img, ColorConversionCodes.COLOR_RGB2GRAY);
var (ret, binary) = cv2.threshold(gray, 0, 255, ThresholdTypes.THRESH_BINARY | ThresholdTypes.THRESH_TRIANGLE);
cv2.imshow("black and white", binary);
cv2.waitKey(0);
```
Video capture from file or camera
```csharp
var vid = cv2.VideoCapture("road.mp4");
var (loaded, frame) = vid.read();
while (loaded)
{
(loaded, frame) = vid.read();
cv2.imshow("video", frame);
}
```
If you want to learn more about the API implementation, please refer to the official [documentation](https://docs.opencv.org/).