Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python';s Numpy.transpose by axes等效于Mat Java_Java_Python_Transpose_Mat - Fatal编程技术网

Python';s Numpy.transpose by axes等效于Mat Java

Python';s Numpy.transpose by axes等效于Mat Java,java,python,transpose,mat,Java,Python,Transpose,Mat,我想在Java openCV上执行相同的函数,但我被转置部分卡住了,因为我没有在Java Mat中找到任何实现,这是Python中的函数: def preprocess(im): # Convert to float32 test_img = im.astype(np.float32) # Extrapolate image with a small border in order obtain an accurate reshaped image after DUC l

我想在Java openCV上执行相同的函数,但我被转置部分卡住了,因为我没有在Java Mat中找到任何实现,这是Python中的函数:

def preprocess(im):
    # Convert to float32
    test_img = im.astype(np.float32)
    # Extrapolate image with a small border in order obtain an accurate reshaped image after DUC layer
    test_shape = [im.shape[0],im.shape[1]]
    cell_shapes = [math.ceil(l / 8)*8 for l in test_shape]
    test_img = cv.copyMakeBorder(test_img, 0, max(0, int(cell_shapes[0]) - im.shape[0]), 0, max(0, int(cell_shapes[1]) - im.shape[1]), cv.BORDER_CONSTANT, value=rgb_mean)
    test_img = np.transpose(test_img, (2, 0, 1))
    # subtract rbg mean
    for i in range(3):
        test_img[i] -= rgb_mean[i]
    test_img = np.expand_dims(test_img, axis=0)
    # convert to ndarray
    test_img = mx.ndarray.array(test_img)
    return test_img
这是我的Java实现:

Mat src, dst = new Mat();
    int top, bottom, left, right;
    int borderType = Core.BORDER_CONSTANT;
    src = Imgcodecs.imread("name", Imgcodecs.IMREAD_COLOR);
    int[] shapes = {src.height(),src.width()};
    double[] cellShapes = new double[shapes.length];
    for (int i = 0; i<shapes.length;i++){
        cellShapes[i] = Math.ceil(shapes[0]/8)*8;
    }

    top = 0;
    bottom = Math.max(0,(int)cellShapes[0]-shapes[0]);
    left = 0;
    right = Math.max(0,(int)cellShapes[1]-shapes[1]);

    Scalar value = Core.mean(src);

    Core.copyMakeBorder( src, dst, top, bottom, left, right, borderType, value);
    /*
    transpose stuff
     */
    Mat nMat = new Mat();
    Core.subtract(dst,value,nMat);

    float[] image = new float[(int)((nMat.total())) * nMat.channels()];
    dst.get(0,0,image);
Mat src,dst=new Mat();
int顶部、底部、左侧、右侧;
int borderType=Core.BORDER_常量;
src=Imgcodecs.imread(“名称”,Imgcodecs.imread\u颜色);
int[]shapes={src.height(),src.width()};
double[]cellShapes=新的double[shapes.length];
对于(int i=0;i