Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 9f63ba7

Browse files
committed
test: add testing case for openCV
1 parent 2a523c9 commit 9f63ba7

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/geometry/__tests__/getPerspectiveWarp.test.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Image } from '../../Image.js';
2-
import { readSync } from '../../load/read.js';
32
import getPerspectiveWarp from '../getPerspectiveWarp.js';
43

5-
describe('warping legacy tests', () => {
4+
describe('warping tests', () => {
65
it('resize without rotation', () => {
76
const image = new Image(3, 3, {
87
data: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]),
@@ -40,13 +39,14 @@ describe('warping legacy tests', () => {
4039
expect(result.width).not.toBeGreaterThan(4);
4140
expect(result.height).not.toBeGreaterThan(2);
4241
});
43-
});
44-
describe('openCV comparison', () => {
45-
it('image of plants', () => {
46-
const image = readSync('./src/geometry/__tests__/plants.png');
42+
43+
test('openCV comparison', () => {
44+
const image = testUtils.load('various/plants.png');
45+
4746
const openCvResult = testUtils.load(
4847
'opencv/test_perspective_warp_plants.png',
4948
);
49+
5050
const points = [
5151
{ column: 166.5, row: 195 },
5252
{ column: 858.5, row: 9 },
@@ -57,11 +57,20 @@ describe('openCV comparison', () => {
5757
width: 1080,
5858
height: 810,
5959
});
60+
const croppedPieceOpenCv = openCvResult.crop({
61+
origin: { column: 45, row: 0 },
62+
width: 400,
63+
height: 400,
64+
});
65+
66+
const croppedPiece = result.crop({
67+
origin: { column: 45, row: 0 },
68+
width: 400,
69+
height: 400,
70+
});
71+
6072
expect(result.width).toEqual(openCvResult.width);
6173
expect(result.height).toEqual(openCvResult.height);
62-
expect(result.getValue(0, 0, 0)).toEqual(openCvResult.getValue(0, 0, 0));
63-
expect(result.getValue(22, 22, 0)).toEqual(
64-
openCvResult.getValue(22, 22, 0),
65-
);
74+
expect(croppedPiece).toEqual(croppedPieceOpenCv);
6675
});
6776
});

src/geometry/getPerspectiveWarp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,5 @@ function projectionPoint(
316316
(a * x + b * y + c) / (g * x + h * y + 1),
317317
(d * x + e * y + f) / (g * x + h * y + 1),
318318
];
319-
return image.getValue(Math.floor(newX), Math.floor(newY), channel);
319+
return image.getValue(Math.round(newX), Math.round(newY), channel);
320320
}

test/TestImagePath.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export type TestImagePath =
7474
| 'opencv/testConvolution.png'
7575
| 'opencv/testGaussianBlur.png'
7676
| 'opencv/testInterpolate.png'
77+
| 'opencv/test_perspective_warp_plants.png'
7778
| 'opencv/testReflect.png'
7879
| 'opencv/test_resize_bicubic_larger.png'
7980
| 'opencv/test_resize_bicubic_same.png'
@@ -95,6 +96,7 @@ export type TestImagePath =
9596
| 'ssim/ssim-saltPepper.png'
9697
| 'various/alphabet.jpg'
9798
| 'various/grayscale_by_zimmyrose.png'
99+
| 'various/plants.png'
98100
| 'various/screws.png'
99101
| 'various/sudoku.jpg'
100102
| 'various/without-metadata.jpg';
-130 KB
Loading

test/img/various/plants.png

2.35 MB
Loading

0 commit comments

Comments
 (0)