python opencv TypeError: Layout of the output array incompatible with cv::Mat

前端 未结 5 1118
温柔的废话
温柔的废话 2021-01-02 01:54

I\'m using the selective search here: http://koen.me/research/selectivesearch/ This gives possible regions of interest where an object might be. I want to do some processing

5条回答
  •  佛祖请我去吃肉
    2021-01-02 02:11

    Just for the sake of completeness, it seems that many of us have used the solution of Etienne Perot above, minus .copy(). Converting the array type to int is enough. For example, when using the Hough transform:

        # Define the Hough transform parameters
        rho,theta,threshold,min,max = 1, np.pi/180, 30, 40, 60  
    
        image = ima.astype(np.uint8) # assuming that ima is an image.
    
        # Run Hough on edge detected image
        lines = cv2.HoughLinesP(sob, rho, theta, threshold, np.array([]), min, max)
    
        # Iterate over the output "lines" and draw lines on the blank 
        line_image = np.array([[0 for col in range(x)] for row in range(y)]).astype(np.uint8)
    
        for line in lines: # lines are series of (x,y) coordinates
            for x1,y1,x2,y2 in line:
                cv2.line(line_image, (x1,y1), (x2,y2), (255,0,0), 10)
    

    Only then could the data be plotted out using plt.imshow()

提交回复
热议问题