Python Forum
Segmentation fault (core dumped)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Segmentation fault (core dumped)
#1
Any idea what is wrong with this code here and gives me Segmentation fault (core dumped)??? I got the code from here:
https://docs.opencv.org/3.0-beta/doc/py_...homography

This is the code:

import numpy as np
import cv2
from matplotlib import pyplot as plt
print("1")
MIN_MATCH_COUNT = 10
print("2")
img1 = cv2.imread("/Homography/car.jpg",0)          # queryImage
print("3")
img2 = cv2.imread("/Homography/scenery.jpg",0) # trainImage
print("4")
# Initiate SIFT detector
sift = cv2.SIFT()
print("5")
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
print("6")
kp2, des2 = sift.detectAndCompute(img2,None)
print("7")
FLANN_INDEX_KDTREE = 0
print("8")
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
print("9")
search_params = dict(checks = 50)
print("10")

flann = cv2.FlannBasedMatcher(index_params, search_params)
print("11")
matches = flann.knnMatch(des1,des2,k=2)
print("12")
# store all the good matches as per Lowe's ratio test.
good = []
print("13")
for m,n in matches:
    print("14")
    if m.distance < 0.7*n.distance:
        print("15")
        good.append(m)
        
if len(good)>MIN_MATCH_COUNT:
    print("16")
    src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
    print("17")
    dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)
    print("18")
    M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
    print("19")
    matchesMask = mask.ravel().tolist()
    print("20")
    h,w = img1.shape
    print("21")
    pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
    print("22")
    dst = cv2.perspectiveTransform(pts,M)
    print("23")
    img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA)
    print("24")
else:
    print("Not enough matches are found - %d/%d" % (len(good),MIN_MATCH_COUNT))
    print("25")
    matchesMask = None
    print("26")
    
draw_params = dict(matchColor = (0,255,0), # draw matches in green color
                   singlePointColor = None,
                   matchesMask = matchesMask, # draw only inliers
                   flags = 2)
print("27")
img3 = cv2.drawMatches(img1,kp1,img2,kp2,good,None,**draw_params)
print("28")
plt.imshow(img3, 'gray'),plt.show()
print("29")
The error I get is this:

Error:
1 2 3 4 5 Segmentation fault (core dumped)
Reply


Messages In This Thread
Segmentation fault (core dumped) - by hobbyist - Jun-07-2021, 11:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Illegal instruction (core dumped) when import pandas. amandacstr 1 2,142 Dec-31-2022, 11:31 PM
Last Post: stevendaprano
  make: *** [Makefile:29: all] Segmentation fault Anldra12 2 1,919 May-01-2022, 06:17 PM
Last Post: Anldra12
  ImportError: /home/ali/Documents/test/charm/core/crypto/AES.cpython-39-x86_64-linux-g Anldra12 0 1,257 Apr-28-2022, 07:13 AM
Last Post: Anldra12
  Python script in Ubuntu core Nithin_Kumar 1 3,397 May-11-2021, 01:14 AM
Last Post: Skaperen
  Segmentation fault with large files kusal1 3 2,790 Oct-01-2019, 07:32 AM
Last Post: Gribouillis
  OpenCV - Segmentation fault samtwilliams 6 7,328 Sep-18-2019, 12:01 AM
Last Post: Larz60+
  Multiple calls to Python interpreter embedded in C++ application yield segmentation f mmoelle1 0 2,859 Mar-21-2019, 08:54 PM
Last Post: mmoelle1
  Segmentation fault when connecting to modbus device with Libmodbus alice 0 2,476 Dec-18-2018, 04:03 PM
Last Post: alice
  Debugging a seg fault tidymax 1 2,881 Oct-31-2018, 02:58 PM
Last Post: ichabod801
  calling python function in c++ callback getting segmentation fault error Jotirling 3 7,201 Oct-26-2017, 08:55 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020