Code Monkey home page Code Monkey logo

Comments (8)

ducha-aiki avatar ducha-aiki commented on July 17, 2024

https://github.com/ducha-aiki/affnet/blob/master/examples/hesaffnet/WBS%20demo.ipynb
does the same, except the last part of your code, which you should add yourself:


 # Find homography
  h, mask = cv2.findHomography(points1, points2, cv2.RANSAC)
 
  # Use homography
  height, width, channels = im2.shape
  im1Reg = cv2.warpPerspective(im1, h, (width, height))

from affnet.

yash1996 avatar yash1996 commented on July 17, 2024

Thanks for showing the the direction.
But I need some help in converting LAFs into cv2.Keypoints vectors or points to find the homography to map the image.
In the LAF.py I found

def LAF2pts(LAF, n_pts = 50):
    a = np.linspace(0, 2*np.pi, n_pts);
    x = [0]
    x.extend(list(np.sin(a)))
    x = np.array(x).reshape(1,-1)
    y = [0]
    y.extend(list(np.cos(a)))
    y = np.array(y).reshape(1,-1)
    HLAF = np.concatenate([LAF, np.array([0,0,1]).reshape(1,3)])
    H_pts =np.concatenate([x,y,np.ones(x.shape)])
    H_pts_out = np.transpose(np.matmul(HLAF, H_pts))
    H_pts_out[:,0] = H_pts_out[:,0] / H_pts_out[:, 2]
    H_pts_out[:,1] = H_pts_out[:,1] / H_pts_out[:, 2]
    return H_pts_out[:,0:2]```

from affnet.

yash1996 avatar yash1996 commented on July 17, 2024

Thanks for showing the direction
but I also need to convert LAFs to cv2.Keypoints format or points to get the homography of the image,

I found LAF.py

def LAF2pts(LAF, n_pts = 50):
    a = np.linspace(0, 2*np.pi, n_pts);
    x = [0]
    x.extend(list(np.sin(a)))
    x = np.array(x).reshape(1,-1)
    y = [0]
    y.extend(list(np.cos(a)))
    y = np.array(y).reshape(1,-1)
    HLAF = np.concatenate([LAF, np.array([0,0,1]).reshape(1,3)])
    H_pts =np.concatenate([x,y,np.ones(x.shape)])
    H_pts_out = np.transpose(np.matmul(HLAF, H_pts))
    H_pts_out[:,0] = H_pts_out[:,0] / H_pts_out[:, 2]
    H_pts_out[:,1] = H_pts_out[:,1] / H_pts_out[:, 2]
    return H_pts_out[:,0:2]

from affnet.

yash1996 avatar yash1996 commented on July 17, 2024

I used the following methode of getting the Keypoints from Local Affine Features (LAFs)

keypoints1  = list(map(lambda x:cv2.KeyPoint(x=x[0],y=x[1], _size = 2),LAFs1.numpy()[:,:,2]))
keypoints2 = list(map(lambda x:cv2.KeyPoint(x=x[0],y=x[1], _size = 2),LAFs2.numpy()[:,:,2]))

# Draw top matches
imMatches = cv2.drawMatches(im1,keypoints1, im2,keypoints2 , matches, None)
cv2.imwrite("matches.jpg", imMatches)
#cv2_imshow(imMatches)
# Extract location of good matches
points1 = np.zeros((len(matches), 2), dtype=np.float32)
points2 = np.zeros((len(matches), 2), dtype=np.float32)

for i, match in enumerate(matches):
  points1[i, :] = keypoints1[match.queryIdx].pt
  points2[i, :] = keypoints2[match.trainIdx].pt

# Find homography
h, mask = cv2.findHomography(points1, points2, cv2.RANSAC)
print(img2.shape)
# Use homography
height, width, channels = im2.shape
im1Reg = cv2.warpPerspective(im2, h, (width, height))

matches (1)

Although the matches are good but it doesn't warps the image as expected.
I am getting better warping using ORB/SIFT from opencv itself.

Is there something wrong in this implementation ?

from affnet.

yash1996 avatar yash1996 commented on July 17, 2024

Considering the fact that the view point difference is lesser than 10 degrees

from affnet.

ducha-aiki avatar ducha-aiki commented on July 17, 2024

Well, for viewpoint difference < 10 degrees you don`t need HardNet or AffNet, it would be overkill.
How many matches and detections do you get with opencv SIFT and with this repo? It might be the issue of detector threshold.
Could you also post the warped images from all methods?

from affnet.

yash1996 avatar yash1996 commented on July 17, 2024

After playing around with the thresholds and number of matches, I am getting the following results.
Input Images:
1st image -
laptop_table
2nd image
table

Affnet Matches
matches

Results
After warping the output using the affnet model
affnet_output (1)

After warping the output using the SIFT model
sift_output

After warping the output using the ORB model
orb_output

from affnet.

ducha-aiki avatar ducha-aiki commented on July 17, 2024

I don`t see any huge difference actually. What is your final goal?

from affnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.