OpenCV resize fails on large image with “error: (-215) ssize.area() > 0 in function cv::resize”

后端 未结 13 2186
醉酒成梦
醉酒成梦 2021-01-01 10:08

I\'m using OpenCV 3.0.0 and Python 3.4.3 to process a very large RGB image (107162,79553,3). While I\'m trying to resize it using the following code:

import         


        
13条回答
  •  情歌与酒
    2021-01-01 10:22

    For me the following work-around worked:

    • split the array up into smaller sub arrays
    • resize the sub arrays
    • merge the sub arrays again

    Here the code:

    def split_up_resize(arr, res):
        """
        function which resizes large array (direct resize yields error (addedtypo))
        """
    
        # compute destination resolution for subarrays
        res_1 = (res[0], res[1]/2)
        res_2 = (res[0], res[1] - res[1]/2)
    
        # get sub-arrays
        arr_1 = arr[0 : len(arr)/2]
        arr_2 = arr[len(arr)/2 :]
    
        # resize sub arrays
        arr_1 = cv2.resize(arr_1, res_1, interpolation = cv2.INTER_LINEAR)
        arr_2 = cv2.resize(arr_2, res_2, interpolation = cv2.INTER_LINEAR)
    
        # init resized array
        arr = np.zeros((res[1], res[0]))
    
        # merge resized sub arrays
        arr[0 : len(arr)/2] = arr_1
        arr[len(arr)/2 :] = arr_2
    
        return arr
    

提交回复
热议问题