Skip to content

Commit 8b6120a

Browse files
Copilotttt43ttt
andauthored
Fix boxPoints type definition to match runtime behavior (#97)
* Initial plan * Fix boxPoints type definition to match runtime behavior Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com> * Improve boxPoints test to check actual coordinate values Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
1 parent 1871ae4 commit 8b6120a

File tree

5 files changed

+58
-31
lines changed

5 files changed

+58
-31
lines changed

src/types/opencv/QRCodeDetector.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import type {
99

1010
/**
1111
* QR Code detection and decoding class.
12-
*
12+
*
1313
* This class implements QR code detection and decoding functionality.
1414
* It can detect QR codes in an image and decode their content.
15-
*
15+
*
1616
* Source:
1717
* [opencv2/objdetect.hpp](https://github.com/opencv/opencv/tree/master/modules/objdetect/include/opencv2/objdetect.hpp).
1818
*/
@@ -24,49 +24,49 @@ export declare class QRCodeDetector {
2424

2525
/**
2626
* Detects QR code in image and returns the quadrangle containing the code.
27-
*
27+
*
2828
* @param img grayscale or color (BGR) image containing (or not) QR code.
2929
* @param points Output vector of vertices of the minimum-area quadrangle containing the code.
3030
*/
3131
public detect(img: InputArray, points: OutputArray): bool;
3232

3333
/**
3434
* Decodes QR code in image once it's found by the detect() method.
35-
*
35+
*
3636
* @param img grayscale or color (BGR) image containing QR code.
3737
* @param points Quadrangle vertices found by detect() method (or some other algorithm).
3838
* @param straight_qrcode The optional output image containing rectified and binarized QR code
3939
*/
4040
public decode(
4141
img: InputArray,
4242
points: InputArray,
43-
straight_qrcode?: OutputArray
43+
straight_qrcode?: OutputArray,
4444
): String;
4545

4646
/**
4747
* Both detects and decodes QR code
48-
*
48+
*
4949
* @param img grayscale or color (BGR) image containing QR code.
5050
* @param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found.
5151
* @param straight_qrcode The optional output image containing rectified and binarized QR code
5252
*/
5353
public detectAndDecode(
5454
img: InputArray,
5555
points?: OutputArray,
56-
straight_qrcode?: OutputArray
56+
straight_qrcode?: OutputArray,
5757
): String;
5858

5959
/**
6060
* Detects QR codes in image and returns the vector of the quadrangles containing the codes.
61-
*
61+
*
6262
* @param img grayscale or color (BGR) image containing (or not) QR codes.
6363
* @param points Output vector of vector of vertices of the minimum-area quadrangle containing the codes.
6464
*/
6565
public detectMulti(img: InputArray, points: OutputArrayOfArrays): bool;
6666

6767
/**
6868
* Decodes QR codes in image once it's found by the detectMulti() method.
69-
*
69+
*
7070
* @param img grayscale or color (BGR) image containing QR codes.
7171
* @param points vector of Quadrangle vertices found by detectMulti() method (or some other algorithm).
7272
* @param decoded_info UTF8-encoded output vector of String or empty vector of String if the codes cannot be decoded.
@@ -76,12 +76,12 @@ export declare class QRCodeDetector {
7676
img: InputArray,
7777
points: InputArray,
7878
decoded_info: any,
79-
straight_qrcode?: OutputArrayOfArrays
79+
straight_qrcode?: OutputArrayOfArrays,
8080
): bool;
8181

8282
/**
8383
* Both detects and decodes QR codes
84-
*
84+
*
8585
* @param img grayscale or color (BGR) image containing QR codes.
8686
* @param decoded_info UTF8-encoded output vector of String or empty vector of String if the codes cannot be decoded.
8787
* @param points optional output vector of vertices of the found QR code quadrangles. Will be empty if not found.
@@ -91,7 +91,7 @@ export declare class QRCodeDetector {
9191
img: InputArray,
9292
decoded_info: any,
9393
points?: OutputArrayOfArrays,
94-
straight_qrcode?: OutputArrayOfArrays
94+
straight_qrcode?: OutputArrayOfArrays,
9595
): bool;
9696

9797
/**
@@ -108,4 +108,4 @@ export declare class QRCodeDetector {
108108
* Releases the object
109109
*/
110110
public delete(): void;
111-
}
111+
}

src/types/opencv/QRCodeDetectorAruco.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ export declare class QRCodeDetectorAruco_Params {
2828

2929
/**
3030
* QR Code detection and decoding class using Aruco-based detection.
31-
*
31+
*
3232
* This class implements QR code detection and decoding functionality using
3333
* Aruco marker detection techniques for improved robustness.
34-
*
34+
*
3535
* Source:
3636
* [opencv2/objdetect.hpp](https://github.com/opencv/opencv/tree/master/modules/objdetect/include/opencv2/objdetect.hpp).
3737
*/
@@ -43,56 +43,56 @@ export declare class QRCodeDetectorAruco {
4343

4444
/**
4545
* QRCodeDetectorAruco constructor with parameters
46-
*
46+
*
4747
* @param params QRCodeDetectorAruco parameters
4848
*/
4949
public constructor(params: QRCodeDetectorAruco_Params);
5050

5151
/**
5252
* Detects QR code in image and returns the quadrangle containing the code.
53-
*
53+
*
5454
* @param img grayscale or color (BGR) image containing (or not) QR code.
5555
* @param points Output vector of vertices of the minimum-area quadrangle containing the code.
5656
*/
5757
public detect(img: InputArray, points: OutputArray): bool;
5858

5959
/**
6060
* Decodes QR code in image once it's found by the detect() method.
61-
*
61+
*
6262
* @param img grayscale or color (BGR) image containing QR code.
6363
* @param points Quadrangle vertices found by detect() method (or some other algorithm).
6464
* @param straight_qrcode The optional output image containing rectified and binarized QR code
6565
*/
6666
public decode(
6767
img: InputArray,
6868
points: InputArray,
69-
straight_qrcode?: OutputArray
69+
straight_qrcode?: OutputArray,
7070
): String;
7171

7272
/**
7373
* Both detects and decodes QR code
74-
*
74+
*
7575
* @param img grayscale or color (BGR) image containing QR code.
7676
* @param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found.
7777
* @param straight_qrcode The optional output image containing rectified and binarized QR code
7878
*/
7979
public detectAndDecode(
8080
img: InputArray,
8181
points?: OutputArray,
82-
straight_qrcode?: OutputArray
82+
straight_qrcode?: OutputArray,
8383
): String;
8484

8585
/**
8686
* Detects QR codes in image and returns the vector of the quadrangles containing the codes.
87-
*
87+
*
8888
* @param img grayscale or color (BGR) image containing (or not) QR codes.
8989
* @param points Output vector of vector of vertices of the minimum-area quadrangle containing the codes.
9090
*/
9191
public detectMulti(img: InputArray, points: OutputArrayOfArrays): bool;
9292

9393
/**
9494
* Decodes QR codes in image once it's found by the detectMulti() method.
95-
*
95+
*
9696
* @param img grayscale or color (BGR) image containing QR codes.
9797
* @param points vector of Quadrangle vertices found by detectMulti() method (or some other algorithm).
9898
* @param decoded_info UTF8-encoded output vector of String or empty vector of String if the codes cannot be decoded.
@@ -102,12 +102,12 @@ export declare class QRCodeDetectorAruco {
102102
img: InputArray,
103103
points: InputArray,
104104
decoded_info: any,
105-
straight_qrcode?: OutputArrayOfArrays
105+
straight_qrcode?: OutputArrayOfArrays,
106106
): bool;
107107

108108
/**
109109
* Both detects and decodes QR codes
110-
*
110+
*
111111
* @param img grayscale or color (BGR) image containing QR codes.
112112
* @param decoded_info UTF8-encoded output vector of String or empty vector of String if the codes cannot be decoded.
113113
* @param points optional output vector of vertices of the found QR code quadrangles. Will be empty if not found.
@@ -117,7 +117,7 @@ export declare class QRCodeDetectorAruco {
117117
img: InputArray,
118118
decoded_info: any,
119119
points?: OutputArrayOfArrays,
120-
straight_qrcode?: OutputArrayOfArrays
120+
straight_qrcode?: OutputArrayOfArrays,
121121
): bool;
122122

123123
/**
@@ -127,7 +127,7 @@ export declare class QRCodeDetectorAruco {
127127

128128
/**
129129
* Set detector parameters
130-
*
130+
*
131131
* @param params QRCodeDetectorAruco parameters
132132
*/
133133
public setDetectorParameters(params: QRCodeDetectorAruco_Params): void;
@@ -136,4 +136,4 @@ export declare class QRCodeDetectorAruco {
136136
* Releases the object
137137
*/
138138
public delete(): void;
139-
}
139+
}

src/types/opencv/imgproc_shape.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export declare function boundingRect(array: InputArray): Rect;
6565
*
6666
* @param box The input rotated rectangle. It may be the output of
6767
*
68-
* @param points The output array of four vertices of rectangles.
68+
* @returns An array of four vertices of the rectangle (Point2f[])
6969
*/
70-
export declare function boxPoints(box: RotatedRect, points: OutputArray): void;
70+
export declare function boxPoints(box: RotatedRect): Point2f[];
7171

7272
/**
7373
* image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0

src/types/opencv/objdetect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ export declare const CASCADE_FIND_BIGGEST_OBJECT: any; // initializer: = 4
103103
export declare const CASCADE_DO_ROUGH_SEARCH: any; // initializer: = 8
104104

105105
export { QRCodeDetector } from "./QRCodeDetector";
106-
export { QRCodeDetectorAruco, QRCodeDetectorAruco_Params } from "./QRCodeDetectorAruco";
106+
export {
107+
QRCodeDetectorAruco,
108+
QRCodeDetectorAruco_Params,
109+
} from "./QRCodeDetectorAruco";

test/rect.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@ describe("rect", () => {
1616
expect(Math.round(points[0].x)).toBe(cv.RotatedRect.boundingRect(rect).x);
1717
expect(Math.round(points[1].y)).toBe(cv.RotatedRect.boundingRect(rect).y);
1818
});
19+
20+
it("test boxPoints function", async () => {
21+
const center = new cv.Point(50, 40);
22+
const size = new cv.Size(80, 30);
23+
const angle = 25;
24+
const rotatedRect = new cv.RotatedRect(center, size, angle);
25+
26+
// Test that boxPoints accepts one argument and returns Point2f[]
27+
const points = cv.boxPoints(rotatedRect);
28+
29+
// Verify it returns 4 points
30+
expect(points.length).toBe(4);
31+
32+
// Check the actual values - boxPoints should return the same result as RotatedRect.points
33+
const expectedPoints = cv.RotatedRect.points(rotatedRect);
34+
expect(points[0].x).toBeCloseTo(expectedPoints[0].x, 5);
35+
expect(points[0].y).toBeCloseTo(expectedPoints[0].y, 5);
36+
expect(points[1].x).toBeCloseTo(expectedPoints[1].x, 5);
37+
expect(points[1].y).toBeCloseTo(expectedPoints[1].y, 5);
38+
expect(points[2].x).toBeCloseTo(expectedPoints[2].x, 5);
39+
expect(points[2].y).toBeCloseTo(expectedPoints[2].y, 5);
40+
expect(points[3].x).toBeCloseTo(expectedPoints[3].x, 5);
41+
expect(points[3].y).toBeCloseTo(expectedPoints[3].y, 5);
42+
});
1943
});

0 commit comments

Comments
 (0)