Reputation: 13
Im trying to get the camera feed for gesture recognition working with OpenCV. I have the model trained I just need to get the camera working and I should be able to recognize sign language. Heres the full error:
OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in cv::Mat::locateROI, file C:\ci\opencv_1512688052760\work\modules\core\src\matrix.cpp, line 991
Traceback (most recent call last):
File "ASL.py", line 28, in <module>
blur = cv2.GaussianBlur(grey, value, 0)
cv2.error: C:\ci\opencv_1512688052760\work\modules\core\src\matrix.cpp:991: error: (-215) dims <= 2 && step[0] > 0 in function cv::Mat::locateROI
My code:
while(cap.isOpened()):
print("while entered")
_,img=cap.read()
cv2.rectangle(img,(900,100),(1300,500),(255,0,0),3) # bounding box which captures ASL sign to be detected by the system
crop_img = img[100:500,900:1300]
# convert to grayscale
grey = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY)
# applying gaussian blur
value = (11, 11)
blur = cv2.GaussianBlur(grey, value, 0)
skin_ycrcb_min = np.array((0, 138, 67))
skin_ycrcb_max = np.array((255, 173, 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)
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
elif 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()
Upvotes: 1
Views: 924
Reputation: 171
I had the same problem just a few months ago. All you have to do is to make sure that your "grey" variable is not None.
Put this code just before the blur:
if grey is not None:
blur = cv2.GaussianBlur(grey, value, 0)
Leave everything else as it is. Hope this helps!
Upvotes: 1