Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
OpenCVを使ってみよう.pdf
Search
linyixain
December 10, 2019
Programming
510
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OpenCVを使ってみよう.pdf
linyixain
December 10, 2019
More Decks by linyixain
See All by linyixain
AITRIOSとNode-RED
linyixian
0
130
Algyan イベント振り返り
linyixian
0
400
.NET nanoFramework programming
linyixian
0
430
Azure Blob Storage on IoT Edge
linyixian
0
520
ALGYAN関西支部2019.pdf
linyixian
0
720
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.2k
dRuby over BLE
makicamel
2
380
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
Oxcを導入して開発体験が向上した話
yug1224
4
320
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
180
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
200
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
710
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
700
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
110
Creating Composable Callables in Contemporary C++
rollbear
0
150
Featured
See All Featured
The Invisible Side of Design
smashingmag
302
52k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Believing is Seeing
oripsolob
1
150
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
A Modern Web Designer's Workflow
chriscoyier
698
190k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
HDC tutorial
michielstock
2
720
GitHub's CSS Performance
jonrohan
1033
470k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Transcript
OpenCVを使ってみよう 2019/12/10 株式会社リンシステムズ 林 宜憲(Yoshinori Hayashi) @linyixian
自己紹介 林 宜憲(はやし よしのり)@linyixian 株式会社リンシステムズ Microsoft MVP for Windows Development
IoTデバイスについてなんかやってます。 AIについてもちょっとだけやってます。
画像認識ってなに? ・今のはやりはカメラに映った映像の内容を理解すること ディープラーニングなどを利用してリアルタイムに映像を解析 できるようになっています。 ・以前からあるのはデジカメの顔検出機能 今日はこの機能をRasPiとカメラを使ってプログラミングします。
人を検出するには 人が写っている画像と写っていない画像を大量(数千枚・・・)に用意して機 械学習を行います。 精度を上げようとすると大量の学習と画像の用意が必要・・・ しかし、先人が学習したモデルがあるので今はそれを利用すれば簡単に検出で きます。
OpenCVとは ・OpenCV(正式名称: Open Source Computer Vision Library)はオープン ソースの画像処理ライブラリ
・画像変換、特徴点抽出、物体認識、機械学習、GUI、カメラビデオ等のコン トロール、ファイル処理など画像に関する様々な機能を持つライブラリ集と なっています。 ・主に対応しているプログラミング言語はC++、Python、JAVAです。その他の 言語でもラッパーライブラリなどがあります。
RaspberryPiにOpenCVをインストール ・RaspberryPiのコンソールを開きます。 ・次に以下のコマンドを実行します。 $ sudo apt update $ sudo
apt upgrade $ sudo apt install libqt4-test libqtgui4 libjasper1 libatlas-base-dev libhdf5-dev $ sudo pip3 install opencv-python==4.1.0.25 $ sudo pip3 install opencv-contrib-python=4.1.0.25 これでインストールは完了です。
インストールの確認 コンソール上でPython3を実行します。 $ python3 >>> import cv2 >>> cv2.__version__
バージョンが表示されればインストールはできています。
Raspiカメラで画像(動画)を表示 import cv2 cap=cv2.VideoCapture(0) while(True): ret,frame=cap.read() cv2.imshow(‘Video’,frame) if cv2.waitKey(1)&0xFF==ord(‘q’): break
cap.release() cv2.destroyAllWindows() video.py
人検出機能を追加 先ほどのコードに人検出機能を追加します。 detect.py import cv2 import time faceCascade=cv2.CascadeClassifier('/usr/local/lib/python3.7/dist-packages/cv2/data/haarcascade_frontalface_default.xml') cap=cv2.VideoCapture(0) while(True):
ret,frame=cap.read() gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) faces=faceCascade.detectMultiScale(gray,1.1,3,0,(10,10)) for(x,y,w,h) in faces: cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2) cv2.imshow('Video',frame) if cv2.waitKey(1)&0xFF==ord('q'): break time.sleep(0.1) cap.release() cv2.destroyAllWindows()
参考 インストールがうまくいかない時は次の記事を参考にしてください。 ラズパイ3にOpenCV3/4を簡単に導入 https://qiita.com/mt08/items/e8e8e728cf106ac83218