0

翻转图像时,我试图获得相反的旋转值。我得到了相反的值,但我每次都得到图像未定义的错误。我做错了什么?

const cv = require('/opncvnode/node_modules/opencv4nodejs');
var rotate = 1;
var image = cv.imread('lenna.png');

function flip(image, rotate){
    var flip_img = image.flip(1);
    var rotate = -(rotate);
    return flip_img, rotate;
}

function imageAugmentation(image, rotate){

    var image, rotate = flip(image, rotate);
    return image, rotate;
}

var image2, angle = imageAugmentation(image, rotate);

console.log(angle);
cv.imshowWait('', image2);

错误:

-1

C:\Users\SHAN\Desktop\Img_aug Final\test.js:20
cv.imshowWait('', image2);
   ^
Io::ImshowWait - expected arg1 to be an instance of Mat
(Use `node --trace-uncaught ...` to show where the exception was thrown)
4

1 回答 1

0

错误是无法在 javascript 中同时返回两个值,因此必须在 javascript 中以数组格式返回值

function flip(image, rotate){
    var flip_img = image.flip(1);
    var rotate = -(rotate);
    return [flip_img, rotate];
}

function imageAugmentation(image, rotate){

    var [image, rotate] = flip(image, rotate);
    return [image, rotate];
}
于 2020-09-07T11:26:54.297 回答