Python Python openCV

Tron36

Ensign
Registriert
Jan. 2011
Beiträge
209
Hallo Leute,

hab folgenden Code geschrieben:
Code:
import cv2

cap = cv2.VideoCapture(0)
cv2.namedWindow('Interactive Systems: Towards AR Tracking')
while True:

    # 1. read each frame from the camera (if necessary resize the image)
    #    and extract the SIFT features using OpenCV methods
    #    Note: use the gray image - so you need to convert the image
    # 2. draw the keypoints using cv2.drawKeypoints
    #    There are several flags for visualization - e.g. DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS

    # close the window and application by pressing a key

    # YOUR CODE HERE
    _, frame_img = cap.read()
    gray = cv2.cvtColor(frame_img, cv2.COLOR_BGR2GRAY)
    sift = cv2.xfeatures2d.SIFT_create()
    key_points = sift.detect(gray, None)
    # bad python binding
    img = cv2.drawKeypoints(gray, key_points, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

    ch = cv2.waitKey(1) & 0xFF
    # quit
    if ch == ord('q'):
        break

    cv2.imshow('image', img)

cap.release()
cv2.destroyAllWindows()

Dazu bekomme folgende Fehlermeldung, womit ich nicht weiterkomme:
Code:
Traceback (most recent call last):
  File "D:/02_features.py", line 17, in <module>
    gray = cv2.cvtColor(frame_img, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'

Ich hoffe, ihr könnt mir weiter helfen.

Lg Tron36
 
füg mal vor Zeile 17 folgendes ein:

Code:
frame_img = frame_img.astype('uint8')
 
habs gemacht, dabei kommt folgender fehler auf:

Code:
Traceback (most recent call last):
  File "D:/Uni/MI_Master/4_Semester/MaschinellesSehen_SS2019/02-features/02_features.py", line 17, in <module>
    frame_img = frame_img.astype('uint8')
AttributeError: 'NoneType' object has no attribute 'astype'
 
Dann passt mit deinem Eingang wahrscheinlich was nicht
 
Das wollte ich auch schon fragen, sicher dass überhaupt ein Bild ankommt? Hast du mal getestet ob das Image nicht None ist?
 
Ist das Bild im Original schwarz/weiss?
 
Zurück
Oben