###前提・実現したいこと
OpenCVを用いたボールトラッキングを行うプログラムです。
某サイトのサンプルを丸ごと記載しましたが、なぜエラーがおきているのか、どうすればエラーが起きずに実行できるかが知りたいです。
###発生している問題・エラーメッセージ
line 26, in <module> for ball in detected_balls: 'NoneType' object is not iterable
###該当のソースコード
# -*- coding: utf-8 -*- """ Created on Mon Nov 27 16:59:15 2017 @author: user4 """ import numpy as np import cv2 cap = cv2.VideoCapture("green.mp4") feature_params=dict(maxCorners=100,qualityLevel=.6,minDistance=25,blockSize=9) video_length=699 kernel=np.ones((5,5),np.uint8) frame_num=0 fgbg = cv2.createBackgroundSubtractorMOG2() points=[] while True: ret,frame=cap.read() fgmask=fgbg.apply(frame) fgmask=cv2.morphologyEx(fgmask,cv2.MORPH_OPEN,kernel) detected_balls=cv2.goodFeaturesToTrack(fgmask,**feature_params) for ball in detected_balls: xy=int(ball[0][0]),int(ball[0][1]) cv2.circle(frame,xy,8,(255,0,0),2) points.append(xy) cv2.imshow("img",frame) cv2.waitKey(1) frame_num+=1
###補足情報(言語/FW/ツール等のバージョンなど)
windows7/Anaconda3.4.4/Spyder3(Python3.5)/OpenCV 3.1.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/12/18 08:05