|
| 1 | +// Pre-publish smoke test: exercises the actual .nupkg files about to be pushed to nuget.org, |
| 2 | +// referenced the same way a real consumer would (PackageReference against a NuGet feed, not |
| 3 | +// ProjectReference against source), to catch packaging mistakes (wrong RID asset placement, |
| 4 | +// missing native library, broken dependency graph) that a source-level test can never see. |
| 5 | +// Asserts and sets the process exit code instead of using a test framework, since the point is |
| 6 | +// just "does a freshly `dotnet add package`-d app work at all", not exhaustive API coverage. |
| 7 | +using System.Globalization; |
| 8 | +using OpenCvSharp; |
| 9 | + |
| 10 | +try |
| 11 | +{ |
| 12 | + var version = Cv2.GetVersionString(); |
| 13 | + |
| 14 | + using var mat = new Mat(256, 256, MatType.CV_8UC1, Scalar.All(0)); |
| 15 | + Cv2.Rectangle(mat, new Rect(40, 40, 120, 120), Scalar.All(255), thickness: -1); |
| 16 | + Cv2.Circle(mat, new Point(180, 180), 30, Scalar.All(200), thickness: -1); |
| 17 | + |
| 18 | + using var orb = ORB.Create(500); |
| 19 | + using var descriptors = new Mat(); |
| 20 | + orb.DetectAndCompute(mat, default, out var keypoints, descriptors); |
| 21 | + |
| 22 | + foreach (var ext in new[] { ".jpg", ".png", ".tiff" }) |
| 23 | + { |
| 24 | + var encoded = Cv2.ImEncode(ext, mat, out var buf); |
| 25 | + if (!encoded || buf.Length == 0) |
| 26 | + throw new InvalidOperationException($"ImEncode({ext}) failed or produced an empty buffer"); |
| 27 | + |
| 28 | + using var decoded = Cv2.ImDecode(buf, ImreadModes.Unchanged); |
| 29 | + if (decoded.Empty() || decoded.Size() != mat.Size()) |
| 30 | + throw new InvalidOperationException( |
| 31 | + $"ImDecode({ext}) round trip failed: empty={decoded.Empty()}, size={decoded.Size()}"); |
| 32 | + } |
| 33 | + |
| 34 | + using var blob = Cv2.Dnn.BlobFromImage(mat, size: new Size(64, 64)); |
| 35 | + if (blob.Empty()) |
| 36 | + throw new InvalidOperationException("Cv2.Dnn.BlobFromImage produced an empty blob"); |
| 37 | + |
| 38 | + var blobShape = string.Join('x', Enumerable.Range(0, blob.Dims).Select(blob.Size)); |
| 39 | + |
| 40 | + Console.WriteLine(string.Format( |
| 41 | + CultureInfo.InvariantCulture, |
| 42 | + "ok: OpenCV {0}, ORB keypoints: {1}, dnn blob shape: {2}", |
| 43 | + version, keypoints.Length, blobShape)); |
| 44 | + return 0; |
| 45 | +} |
| 46 | +catch (Exception ex) |
| 47 | +{ |
| 48 | + Console.Error.WriteLine("error: " + ex); |
| 49 | + return 1; |
| 50 | +} |
0 commit comments