2017-12-15 2 views
-1

이 없습니다 나는 검색을 많이했지만 나는 해결책을 찾을 수 없습니다.OpenCV의 파이썬 오류 : 형식 오류 :이 코드 오류가 발생했습니다 실행할 때 'NoneType'개체가</p> <p>.. 더 속성 '__getitem__'

Traceback <most recent call last>: 
File "ASL.py", line 24, in <module> 
img1=img[100:500, 900:1300] 
TypeError: 'NoneType' object has no attribute '__getitem__' 

그리고 이것은 ASL.py 코드입니다!

import cv2 
import numpy as np 
import util as ut 
import svm_train as st 
import re 
model=st.trainSVM(17) 
#create and train SVM model each time coz bug in opencv 3.1.0 svm.load() https://github.com/Itseez/opencv/issues/4969 
cam=int(raw_input("Enter Camera number: ")) 
cap=cv2.VideoCapture(cam) 
font = cv2.FONT_HERSHEY_SIMPLEX 

def nothing(x) : 
    pass 

text= " " 

temp=0 
previouslabel=None 
previousText=" " 
label = [None] 
while(cap.isOpened()): 
    _,img=cap.read() 
    cv2.rectangle(img,(900,100),(1300,500),(255,0,0),3) 
    img1=img[100:500, 900:1300] 
    img_ycrcb = cv2.cvtColor(img1, cv2.COLOR_BGR2YCR_CB) 
    blur = cv2.GaussianBlur(img_ycrcb,(11,11),0) 
    skin_ycrcb_min = np.array((0, 138, 67)) 
    skin_ycrcb_max = np.array((255, 183, 133)) 
    mask = cv2.inRange(blur, skin_ycrcb_min, skin_ycrcb_max) # detecting the hand in the bounding box using skin detection 
    contours,hierarchy = cv2.findContours(mask.copy(),cv2.RETR_EXTERNAL, 2) 
    cnt=ut.getMaxContour(contours,4000)      # using contours to capture the skin filtered image of the hand 
    if cnt!=None: 
     gesture,label=ut.getGestureImg(cnt,img1,mask,model) # passing the trained model for prediction and fetching the result 
     if(label!=None): 
      if(temp==0): 
       previouslabel=label 
      if previouslabel==label : 
       previouslabel=label 
       temp+=1 
      else : 
       temp=0 
      if(temp==40): 
       if(label=='P'): 

        label=" " 
       text= text + label 
       if(label=='Q'): 
        words = re.split(" +",text) 
        words.pop() 
        text = " ".join(words) 
        #text=previousText 
       print text 

     cv2.imshow('PredictedGesture',gesture)    # showing the best match or prediction 
     cv2.putText(img,label,(50,150), font,8,(0,125,155),2) # displaying the predicted letter on the main screen 
     cv2.putText(img,text,(50,450), font,3,(0,0,255),2) 
    cv2.imshow('Frame',img) 
    cv2.imshow('Mask',mask) 
    k = 0xFF & cv2.waitKey(10) 
    if k == 27: 
     break 


cap.release()   
cv2.destroyAllWindows() 

이 코드는 수화를 번역 한 것입니다.

나는 그것을 풀려고했지만 나는 할 수 없었다.

어떤 부분을 변경해야합니까? 더 자세히 자세히 설명합니다. 귀하의 조언에 감사드립니다.

+2

문제점은 오류의 내용과 정확히 같습니다. 'img'의 타입은'None'입니다. – chrisz

답변

1

cap.read()은 성공하지 못했습니다. 따라서 imgNone입니다. 문서에서 :

If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.

관련 문제