matlabopencvcorner-detection

How to detect one chessboard corner?


Given a chessboard image, OpenCV (Matlab and etc.) function can detect chessboard corners very precisely.

Now I have only one chessboard-like corner (Please see two attached images), how can I detect the corner point precisely? Are there any available functions?

If not, Could someone tell me the implementation details of finding chessboard corners in OpenCV? Maybe I can use the similar idea to implement the one-chessboard-corner detection myself.

Thanks.

enter image description here

enter image description here


Solution

  • You can use the Harris Corner detector to find the corner in the image. If you have the Image Processing Toolbox in MATLAB you can use the corner() function to detect the corner: https://uk.mathworks.com/help/images/ref/corner.html

    MATLAB code to detect the corner:

    image = imread('E8UD1.png');
    imageGray  = rgb2gray(image);
    C = corner(imageGray);
    imshow(imageGray);
    hold on;
    plot(C(:,1), C(:,2), 'r*');
    

    Update after comment

    The corner() function does a decent job in detecting the corners but you're right you do get outliers, I would instead recommend a more elaborate algorithm, it's called Shi-Tomasi Corner Detector & Good Features to Track

    Here are the results I get when I run the new image:

    enter image description here

    Still not perfect but you can play around with the parameters for the goodFeaturesToTrack() function

    Here is the code:

    import numpy as np
    import cv2
    
    filename = 'ddNNZ.jpg'
    img = cv2.imread(filename)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    
    corners = cv2.goodFeaturesToTrack(gray,1,0.01,10)
    corners = np.int0(corners)
    
    for i in corners:
        x,y = i.ravel()
        cv2.circle(img,(x,y),3,255,-1)
    
    cv2.imwrite('result.png',img)