用opencvsharp改写这段代码
时间: 2024-03-09 13:47:36 浏览: 54
Opencvsharp示例代码
3星 · 编辑精心推荐
好的,以下是使用OpenCvSharp库重写的代码:
```csharp
using OpenCvSharp;
class Program
{
static void Main(string[] args)
{
Mat img1 = Cv2.ImRead("img1.jpg", ImreadModes.Grayscale);
Mat img2 = Cv2.ImRead("img2.jpg", ImreadModes.Grayscale);
Mat binaryImg1 = new Mat();
Mat binaryImg2 = new Mat();
Cv2.Threshold(img1, binaryImg1, 128, 255, ThresholdTypes.Binary);
Cv2.Threshold(img2, binaryImg2, 128, 255, ThresholdTypes.Binary);
Mat overlap = new Mat();
Cv2.BitwiseAnd(binaryImg1, binaryImg2, overlap);
int overlapPixels = Cv2.CountNonZero(overlap);
double overlapArea = overlapPixels * pixelArea;
}
}
```
请注意,这里使用了OpenCvSharp的方法和枚举来替代了OpenCV的方法和常量。
阅读全文