ypeError Traceback (most recent call last) Cell In[9], line 1 ----> 1…
- User
ypeError Traceback (most recent call last) Cell In[9], line 1 ----> 1 main(r"C:\Users\new\OneDrive\Master of informatics\CIT690G Computer vision\Assignments and tasks\Assignment 2\partII\partII\fishbowl\fishbowl-00.png", r"C:\Users\new\OneDrive\Master of informatics\CIT690G Computer vision\Assignments and tasks\Assignment 2\partII\partII\fishbowl\fishbowl-01.png", "c/results", True)
Cell In[8], line 71, in main(image0_path, image1_path, results_dir, use_lmeds) 69 # Find best matches using Ransac or LMedS 70 if(use_lmeds): ---> 71 homography, inliers01 = lmeds((src, dst), threshold_distance=0.8, threshold_inliers=0.3, max_trials=500) 72 print('3. Using LMedS to find the best matching') 73 title = '3. Best matching after LMedS'
TypeError: cannot unpack non-iterable NoneType object
- Assistant
This error occurs because the function lmeds() is returning a NoneType object, which cannot be unpacked into variables. This could happen if the function is not able to find any good matches or inliers between the two images. A possible solution could be to add some conditions to handle such cases, or to check the input parameters to the function to make sure they are correct.
- User
modify this code to implement lmeds instead of ransac: #RANSAC Algorithm def ransac(data, threshold_distance, threshold_inliers=0, max_trials=200): random_state = np.random.mtrand._rand num_samples = len(data[0]) for num_trials in range(max_trials): # Sample Random 4 point pairs correspondences spl_idxs = random_state.choice(num_samples, 4, replace=False) samples = [d[spl_idxs] for d in data] # Estimate homography H = dlt(samples[0], samples[1]) # Reproject All points using H and compute reprojection error src_pts = np.insert(data[0], 2, 1, axis=1).T dst_pts = np.insert(data[1], 2, 1, axis=1).T projected_pts = np.dot(H, src_pts) error = np.sqrt(np.sum(np.square(dst_pts - (projected_pts / projected_pts[-1])), axis=0)) count_inliers = np.count_nonzero(error < threshold_distance) #Select inliers consistent with the estimate if count_inliers / num_samples > threshold_inliers: inliers = error < threshold_distance src_inliers = src_pts[:, np.argwhere(error < threshold_distance).flatten()][:-1].T dst_inliers = dst_pts[:, np.argwhere(error < threshold_distance).flatten()][:-1].T H = dlt(src_inliers, dst_inliers) break return H, inliers
- Assistant
Here is the modified code implementing LMedS algorithm in place of RANSAC:
code - User
TypeError Traceback (most recent call last) Cell In[17], line 1 ----> 1 main(r"C:\Users\new\OneDrive\Master of informatics\CIT690G Computer vision\Assignments and tasks\Assignment 2\partII\partII\fishbowl\fishbowl-00.png", r"C:\Users\new\OneDrive\Master of informatics\CIT690G Computer vision\Assignments and tasks\Assignment 2\partII\partII\fishbowl\fishbowl-01.png", "c/results", True)
Cell In[16], line 71, in main(image0_path, image1_path, results_dir, use_lmeds) 69 # Find best matches using Ransac or LMedS 70 if(use_lmeds): ---> 71 homography, inliers01 = lmeds((src, dst), threshold_distance=0.8, threshold_inliers=0.3, max_trials=500) 72 print('3. Using LMedS to find the best matching') 73 title = '3. Best matching after LMedS'
TypeError: cannot unpack non-iterable NoneType object
- Assistant
This error is similar to the one mentioned earlier, where the function lmeds() is returning a NoneType object, which cannot be unpacked into variables. The issue might be that the function is not able to find good matches or inliers between the two input images, causing it to return None.
To handle this error, we can add some conditions to check the output of the lmeds() function before trying to unpack it into variables. For example, we can check if the returned homography matrix and inliers array are not NoneType objects before using them. If they are None, we can print an error message or return None to indicate that the function failed to find good matches.
Here is an example modification of the code to handle this error:
- User
- Assistant
Here is the modified code that uses the lmeds algorithm instead of RANSAC:
code