Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit aad2659

Browse files
committed
imgproc: applyColorMap supports cv version < 3.4 && update ts types
1 parent 3512bc6 commit aad2659

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

cc/modules/imgproc/imgprocBindings.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ namespace ImgprocBindings {
4646
int colormap;
4747
bool useUserColor = 0;
4848

49-
// TODO(oyyd) Need better polymorphism support.
5049
bool unwrapRequiredArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
50+
#if CV_VERSION_MINOR < 4
51+
return (Mat::Converter::arg(0, &src, info) ||
52+
IntConverter::optArg(1, &colormap, info));
53+
#endif
54+
55+
#if CV_VERSION_MINOR >= 4
5156
if (info[1]->IsNumber()) {
5257
return (Mat::Converter::arg(0, &src, info) ||
5358
IntConverter::optArg(1, &colormap, info));
@@ -57,15 +62,23 @@ namespace ImgprocBindings {
5762

5863
return (Mat::Converter::arg(0, &src, info) ||
5964
Mat::Converter::arg(1, &userColor, info));
65+
#endif
6066
}
6167

6268
std::string executeCatchCvExceptionWorker() {
69+
#if CV_VERSION_MINOR < 4
70+
cv::applyColorMap(src, dst, colormap);
71+
return "";
72+
#endif
73+
74+
#if CV_VERSION_MINOR >= 4
6375
if (useUserColor) {
6476
cv::applyColorMap(src, dst, userColor);
6577
} else {
6678
cv::applyColorMap(src, dst, colormap);
6779
}
6880
return "";
81+
#endif
6982
}
7083

7184
v8::Local<v8::Value> getReturnValue() { return Mat::Converter::wrap(dst); }

lib/typings/constants.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,19 @@ export const COLOR_YUV420sp2GRAY: number;
352352
export const COLOR_YUV420sp2RGB: number;
353353
export const COLOR_YUV420sp2RGBA: number;
354354
export const COLOR_mRGBA2RGBA: number;
355+
export const COLORMAP_AUTUMN: number;
356+
export const COLORMAP_BONE: number;
357+
export const COLORMAP_JET: number;
358+
export const COLORMAP_WINTER: number;
359+
export const COLORMAP_RAINBOW: number;
360+
export const COLORMAP_OCEAN: number;
361+
export const COLORMAP_SUMMER: number;
362+
export const COLORMAP_SPRING: number;
363+
export const COLORMAP_COOL: number;
364+
export const COLORMAP_HSV: number;
365+
export const COLORMAP_PINK: number;
366+
export const COLORMAP_HOT: number;
367+
export const COLORMAP_PARULA: number;
355368
export const CV_CONTOURS_MATCH_I1: number;
356369
export const CV_CONTOURS_MATCH_I2: number;
357370
export const CV_CONTOURS_MATCH_I3: number;

lib/typings/cv.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface HistAxes {
1818
ranges: number[];
1919
}
2020

21+
export function applyColorMap(src: Mat, colormap: number | Mat): Mat;
2122
export function blobFromImage(image: Mat, scaleFactor?: number, size?: Size, mean?: Vec3, swapRB?: boolean): Mat;
2223
export function blobFromImageAsync(image: Mat, scaleFactor?: number, size?: Size, mean?: Vec3, swapRB?: boolean): Promise<Mat>;
2324
export function blobFromImages(image: Mat[], scaleFactor?: number, size?: Size, mean?: Vec3, swapRB?: boolean): Mat;
@@ -162,4 +163,4 @@ export function drawTextBox(img: Mat, upperLeft: { x: number, y: number }, textL
162163
export function isCustomMatAllocatorEnabled(): boolean;
163164
export function dangerousEnableCustomMatAllocator(): boolean;
164165
export function dangerousDisableCustomMatAllocator(): boolean;
165-
export function getMemMetrics(): { TotalAlloc: number, TotalKnownByJS: number, NumAllocations: number, NumDeAllocations: number };
166+
export function getMemMetrics(): { TotalAlloc: number, TotalKnownByJS: number, NumAllocations: number, NumDeAllocations: number };

0 commit comments

Comments
 (0)