Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
画像処理ライブラリOpenCVの使い方
Search
OHNO
June 20, 2020
Research
1.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
画像処理ライブラリOpenCVの使い方
OHNO
June 20, 2020
More Decks by OHNO
See All by OHNO
自社データを生成AIに活用
planeta
0
120
生成系AIで自データを扱うには
planeta
0
240
外観検査の難しさ
planeta
0
570
儲かるPython
planeta
0
260
画像処理ライブラリOpenCVの使い方0910
planeta
0
1.5k
Pythonによる工業用カメラ画像取得事例
planeta
0
1.5k
SONYのNNC
planeta
0
650
機械学習による動作認識
planeta
0
790
画像類似度計算
planeta
0
2.1k
Other Decks in Research
See All in Research
Easy to Guess, Hard to Verify: Lessons from AIMO 3 for Olympiad-Level AI Mathematics
corochann
0
120
PHTalks Bengaluru - SSRF When All Else Fails
dk999
0
1.2k
Research Engineerという仕事 / Research Engineering: Bridging Research and Business
chck
1
360
MIRU2026 チュートリアル講演2:三次元データ処理の動向
nnchiba
6
5k
第64回CV・PRML勉強会 論文紹介:Linguistic Priors for Visual Decoupling: Towards Symmetric Vision-Brain Alignment
sokikatayama
0
230
某助成金プロジェクト採択に向けて企業研究所のアウトリーチ専任者がやったこと
afroscript
0
190
Google Cloud Next 2026 DM Recap Agentic Data Cloudを添えて / Google Cloud Next 2026 DM Recap
nnaka2992
0
140
La génomique au service de la fromageabilité du lait grâce aux spectres MIR
institudelelevage
PRO
0
130
最先端NLP勉強会2026 論文紹介:Reasoning with Sampling: Your Base Model is Smarter Than You Think (ICLR 2026 paper)
kogoro
4
660
CVPR2026論文紹介_VLMにとって良いvision encoderとは何か?Rethinking Model Selection in VLM Through the Lens of Gromov-Wasserstein Distance
kobayashi31
1
250
敵対生成プロンプト同時探索による内省型プロンプト最適化
kinoue_smarthr
0
430
XDPerf: A High-Performance Traffic Generator Built with WASM and eBPF
takehaya
1
310
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Believing is Seeing
oripsolob
1
230
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
570
The SEO identity crisis: Don't let AI make you average
varn
0
560
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
750
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
The agentic SEO stack - context over prompts
schlessera
0
940
Transcript
画像処理ライブラリ OpenCVの使い方 大野 宏 Python機械学習勉強会in新潟 Restart#11
Pythonでよく使われる画像ライブラリ ・matplotlibグラフ作成ライブラリ 学習回数―認識率の グラフや画像の表示 ・Pillow 画像の回転や拡大縮小など基本的な処理
OpenCV ・無料の画像処理用ライブラリ 最新版は4.3.0 ・マルチプラットフォーム Windows、Linux、Mac、iOS、Android C、C++、Python、Java ・Intel社が開発して公開→Willow Garage社が開発・管理 ・matplotlib や
Pillow より高機能 ・ディープラーニングの前処理や後処理に有効 ・OpenCVだけで傷の検査が出来る場合も
OpenCVの基本的な機能 ・画像の読み込みと表示 ・画像の拡大と縮小 ・画像の回転 ・図形の描画 ・フィルタ処理 ・ラベリング ・2値化
OpenCVのインストール方法 ・ターミナルを開いて pip install opencv-python ・確認 ターミナルでPythonを起動し $python [Enter] 下記の通りに入力して何も表示されなければOK
>>import cv2 [Enter] >> ・Numpyもインストールしておくとよい
画像の読み込みと表示 #カラー img1=cv2.imread("lena.jpg",1) #白黒 img1=cv2.imread("lena.jpg",0) #表示 cv2.imshow ( "img1", img1
) #表示時間 1秒 cv2.waitKey(1000) #保存 cv2.imwrite("img.png" , img1) USBカメラの画像も 簡単に表示できる
画像の拡大と縮小 img1=cv2.imread("building.jpg",1) height = img1.shape[0] width = img1.shape[1] #縮小 img2=cv2.resize(img1,(int(width*0.5),
int(height*(0.5))) cv2.imshow( "img2", img2 ) cv2.waitKey(1000)
画像の反転、回転 img1=cv2.imread("building.jpg",1) img2=cv2.flip(img1,0) #上下反転 0 cv2.imshow ( "img2", img2 )
cv2.waitKey(1000) img2=cv2.flip(img1,1) #左右反転 >0 img2=cv2.flip(img1,-1) #左右反転 <0 img2=cv2.rotate(img1, cv2.ROTATE_90_CLOCKWISE) img2=cv2.rotate(img1, cv2.ROTATE_180) img2=cv2.rotate(img1,cv2.ROTATE_90_COUNTERCLOCKWISE)
画像の回転 img1=cv2.imread("building.jpg",1) height = img1.shape[0] width = img1.shape[1] center =
(int(width/2), int(height/2)) angle = 45.0 scale = 1.0 trans = cv2.getRotationMatrix2D(center, angle , scale) img2 = cv2.warpAffine(img1, trans, (width,height)) cv2.imshow ( "img2", img2 ) cv2.waitKey(1000)
四角形、線、円の描画 img1=cv2.imread("building.jpg",1) cv2.rectangle(img1, (200, 200), (500, 500), (255, 0, 0),
thickness=2, lineType=cv2.LINE_4) cv2.line(img1, (100, 100), (600, 100), (0, 255, 0), thickness=2, lineType=cv2.LINE_4) cv2.circle(img1, (440,400), 100, (0,0,255), thickness=2, lineType=cv2.LINE_4, shift=0) cv2.imshow ( "img", img1 ) cv2.waitKey(1000)
フィルタ処理(平均値) img1=cv2.imread("lena.jpg") #平均値フィルタ img2=cv2.blur(img1,(3,3)) cv2.imshow ( "img2", img2 ) cv2.waitKey(1000)
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
フィルタ処理(Sobel) img1=cv2.imread("building.jpg",0) img3=cv2.Sobel(img1,cv2.CV_32F,1,0) img3=cv2.convertScaleAbs(img3) cv2.imshow ( "img1", img1 ) cv2.imshow
( "img3", img3 ) cv2.waitKey(1000) 横方向に強調→縦線検出 -1 0 1 -2 0 2 -1 0 1
フィルタ処理(Sobel) img1=cv2.imread("building.jpg",0) img2=cv2.Sobel(img1,cv2.CV_32F,0,1) img2=cv2.convertScaleAbs(img2) cv2.imshow ( "img1", img1 ) cv2.imshow
( "img2", img2 ) cv2.waitKey(1000) img3=img2|img3 cv2.imshow ( "img3", img3 ) cv2.waitKey(1000) 縦方向に強調→横線検出 -1 -2 -1 0 0 0 1 2 1
フィルタ処理(Sobel)の結果
フィルタ処理(Canny) 輪郭線を綺麗に抽出するフィルター img1=cv2.imread("building.jpg",0) img2=cv2.Canny(img1,100,200) cv2.imshow ( "img1", img1 ) cv2.imshow
( "img2", img2 ) cv2.waitKey(1000)
2値化とラベリング1 2値化:グレイスケールの画像を適当な値で0と1に分ける ラベリング:1の塊ごとに番号をつける 元画像 ラベルごとに色付け
2値化とラベリング2 img1=cv2.imread("pic1.png”,1) img2=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY) #2値化 ret,img3=cv2.threshold(img2,100,255,cv2.THRESH_BINARY) #ラベリング n,label=cv2.connectedComponents(img3) height = img3.shape[0]
width = img3.shape[1] str1='height:'+str(height)+' width:'+str(width) print(str1) cv2.imshow ( "img3", img3 )
ラベルの色付け colors=[] colors.append([0,0,0]) colors.append([255,0,0]) colors.append([0,255,0]) colors.append([0,0,255]) colors.append([0,255,255]) for y in
range(0,height): for x in range(0,width): if 0<label[y,x]: img1[y,x]=colors[label[y,x]] else: img1[y,x]=[0,0,0] cv2.imshow ( "img1", img1 ) cv2.waitKey(0)
前処理での利用例 煎餅の良・不良の判別をYOLOで行う場合、学習データとし てアノテーションが必要 → OpenCVを使うと作業が楽 良品 不良品(欠けや割れ)
2値化とラベリングで領域検出 ・2値化とラベリングして煎餅の領域を検出する
良・不良のラベル付け ・面積で良・不良を判別してラベルを付ける 良品 不良品 良品
目視で修正 ・誤った半別を目視で修正し、データ作成完了 良品 不良品
画像処理による傷の検査 ・2値化、ラベリング、大きい塊を傷と認識 → 引っ掻き傷は2値化すると線が途切れる ・傷の画像を集め、画像処理(大きさ、濃淡、傾き)で数を 増し、ディープラーニングで判別 現画像 2値画像 直線なら傷 途切れるとノイズ?
参考図書 ・Python、C++ ・各アルゴリズムがどのよう な計算をしているかも記述 ・ネットで検索すると参考にな るもの多数あり