【OpenCV】ラジコン自動運転のためのまだまだ初歩の初歩。。画像検出【チャイナWiFiCam】

スポンサーリンク
広告

昨日の続き

昨日は、WiFiカメラのストリームを調査しました。

【忘備録】WiFi IP camera ストリーミング、コントロール等Vstarcam C7837WIP(W)【OpenCV】
天才ハッカーのComma.ai 天才ハッカーの自動運転プロジェクトがオープンソース化されたので・・ 見てみたんですが・・・どうも...

それを、Pythonで少しいじる。。Pythonの環境は、Spyderで動かしてます。

【画像処理】Windows10に Python3.5 OpenCV3.1を入れてみる【Anaconda】
Open CV の新しいの入れてみようかな? Raspberry Piだと、Pythonとかも最初から入ってて、あんまり悩まずに、Open...

やりたいのは・・・ラズパイ(Raspberry Pi)でラジコン自動運転なんですが・・

【妄想企画】Raspberry Pi 2 と OpenCV 3でラジコンの自動運転!?レースできたらおもろそう
まずは、この動画 OpenCV でpythonでニューラルネットワークで、ラジコンを自動運転しています。 OpenCV Python ...

一気にやるのは、大変なので、ひとつづつ組み合わせで・・まずはレーン検出的なところからやってみようかと。。でもその前に少しカメラで遊んでみます。

Wifi ONVIF Cameraのストリーム映像で、顔を検出して、その顔に合わせて、カメラのPTZ(パン・チルト)を動かして追跡させようかな?っていう例題をしてみようって思っています。

これも一気に行かないので、少しづつ(笑)

練習問題1(FaceDetection)

まずは、いろんなところに転がっている顔画像の検出(FaceDetection)

import cv2

ORG_WINDOW_NAME="org"

faceCascade = cv2.CascadeClassifier("C:\\Users\\tominaga2\\Anaconda3\\pkgs\\opencv3-3.1.0-py35_0\\Library\\etc\\haarcascades\\haarcascade_frontalface_alt2.xml")

img = cv2.imread("image.jpg", cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face = faceCascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(20, 20))

#cv2.namedWindow(ORG_WINDOW_NAME)
#cv2.imshow(ORG_WINDOW_NAME, img)
if len(face) > 0:
 for rect in face:
 cv2.rectangle(img, tuple(rect[0:2]), tuple(rect[0:2]+rect[2:4]), (0, 0,255), thickness=2)
else:
 print("no face")

cv2.imshow("faces",img)
#cv2.imwrite('detected.jpg', img)
cv2.waitKey(0)

cv2.imread って関数で、画像読み込んで、

CascadeClassifier に入れた分類器(正面の顔)で検出できるようにセットして

グレースケールにして、detectMultiScale で 検出して、見つけた数だけ□で囲う。

2016-12-06-4

とりあえず、OpenCVが動くのを確認(^^;

って実はこれでかなりつまずいています(笑)

次はストリームをOpenCVで表示

なんだけど・・・Streamにすると動かない。。ファイルだったら動くのになぁ~

ファイルだと

import cv2

URL = "2_2016-12-06_21-47-59.mp4"
s_video = cv2.VideoCapture(URL)
print(s_video)

while True:
 ret, img = s_video.read()
 cv2.imshow("Stream Video",img)
 key = cv2.waitKey(1) & 0xff
 if key == ord('q'): break

これで動いて・・

こんな感じなんだけど・・・

URL = "rtsp://user:pwd@ip:port/udp/av0_1"

としても、動くって、書いてあるけど・・動かない(^^;

2016-12-06-5

Picture size 0x0 is invalid って出て止まる。

ちなみに、その下のOpenCV Error は ファイルの時でも出てるけど、動いています(笑)

参考にしている所は

OpenCVでIP Cameraの画像を表示してみた
OpenCV 機械学習 Deep learning Caffe の環境構築の備忘録 関連する分野は、 画像認識 CV Computer Vision Windows Ubuntu Android
Reading and Writing Video — OpenCV 3.0.0-dev documentation
Opencv VideoCapture File, Web Camera, RTSP stream
Opencv VideoCapture How to read RTSP stream with opencv on linux with full source code included in this tutorial

RSTPでも取り込めるはずなんだけどなぁ~何か制限があるのかな??

RTSP stream and OpenCV (Python)
I have an IP camera streaming on Linux through rtsp protocol and h264 linux driver. I am able to see the video in VLC with the following address and port: rtsp...

の情報を見ると、OpenCV3.1+Python3.4なら動いたって・・・(笑)

誰か教えて~~ (笑)  opencv_ffmpeg310.dll が問題なような・・・???雰囲気だけ

このストリーム入力ができたら、

GitHub - commaai/openpilot: openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for 250+ supported car makes and models.
openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for 250+ supporte...

とか、Lane detection and Car detection みたいなことができるだろうし・・・

GitHub - funningboy/carCV at 7d34d421965d1762ce97ac935ab8c33c6ac10153
carCV. Contribute to funningboy/carCV development by creating an account on GitHub.

いろいろできそうな感じがするんだけどなぁ~

5/23追記

Stackoverflowに、Videocaptureが動かないという記事があり。。PathとDLLの名前変更でできるという記述を発見。 そろそろ、またやってみるか・・(笑)

OpenCV 2.4 VideoCapture not working on Windows
I'm using Python bindings to OpenCV 2.4 installed with following instructions. My problem is similar to this one, but I need Windows machine solution. Problem...
58down voteaccepted

Add C:\OpenCV\3rdparty\ffmpeg\ to the Windows PATH environment variable or copy opencv_ffmpeg.dll from that directory to C:\Python27\ or to a directory that is in the PATH. Alternatively, use the OpenCV binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

Renaming the opencv_ffmpeg.dll file may also be necessary.

For OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ.dll

For 64-bit OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ_64.dll

With OpenCV 2.4.10, adding C:\opencv\sources\3rdparty\ffmpeg to Windows path and renaming opencv_ffmpeg.dll and opencv_ffmpeg_64.dll to opencv_ffmpeg2410.dll and opencv_ffmpeg2410_64.dll it works ! Thanks 🙂 I am now able to open MJPEG video files – Vincent Feb 18 ’15 at 7:59
Thanks – this works! It’s frustrating that this “silently fails” without that DLL copied in. I’d rather instead of a subtle false, a nice big exception “error, Danger Will Robinson, missing dll <…>” and then die. – Danny Staple Dec 13 ’15 at 21:26
I would recommend the second option (using the OpenCV binaries from lfd.uci.edu/~gohlke/pythonlibs/#opencv). It’s cleaner and pretty straightforward. Thanks for the help. – Victor Oliveira Antonino Dec 13 ’16 at 20:29

コメントを残していただけるとありがたいです

Loading Facebook Comments ...
%d人のブロガーが「いいね」をつけました。