SlideShare a Scribd company logo
1 of 46
Download to read offline
第2回プレ卒研
Android開発入門
~今日の内容~
UIの詳細(レイアウトの種類)
OpenCVで画像処理
TextViewやButtonなどのUIパーツはViewと呼ばれる
Viewの集合 = View Group
UIの詳細
TextView
Button
View ViewGroup
TextView
Button
UIの詳細
setContentView(R.layout.activity_main);
レイアウトをどれにするかを指定する
実はsetContentView()を使って配置できるViewは1つだけ
→だけどレイアウトには複数のViewが・・・・
UIの詳細
setContentView(R.layout.activity_main);
レイアウトをどれにするかを指定する
Viewを継承しているViewGroupを使ってレイアウトを作る!
UIの詳細
setContentView(R.layout.activity_main);
初期レイアウトをどれにするかを指定する
そんなViewGroupにも様々な種類がある
UIの詳細
LinearLayout
Viewを縦または横一列に並べて配置する
android:orientation=“vertical”→
↑
android:orientation=“horizontal”
UIの詳細
TableLayout
Viewを格子状に配置する
<TableRow><TableRow/>
UIの詳細
RelativeLayout
Viewを相対的に配置する
このパーツは☓☓の真下に配置する
中央線右から○○dpずれた場所に配置する
UIの詳細
複数のレイアウトを組み合わせることも可能
LinearLayout
TableLayout
RelativeLayout
複雑なレイアウトの構築が可能になる
Let`s OpenCV
Open CVで画像処理
Let`s OpenCV
Open CV
Intelから公開されているコンピュータビジョンライブラリ
フィルター処理、直線検出、パターン認証、機械学習・・・
Let`s OpenCV
OpenCV for Android
http://sourceforge.net/projects/opencvlibrary/files/
Zipを展開しAndroid StudioでImport Projectを選択
「Create project…」を選択してNext
Let`s OpenCV
プロジェクト名を入力してNext
Let`s OpenCV
全部選択してNext
Let`s OpenCV
Next
Let`s OpenCV
「sdk」をだけを選択してNext
Let`s OpenCV
ターゲットAPIを選択してNext
Let`s OpenCV
チェックを確認してFinish
Let`s OpenCV
Build->Rebuild Peojectを選択
Let`s OpenCV
新しいプロジェクトを作成しFile->Import Moduleで
「OpenCV-2.4.10-android-sdk¥sdk¥java¥sdk.iml」を選択
Let`s OpenCV
Finishを選択
Let`s OpenCV
プロジェクト名->app->build.gradleを選択
「dependevcies」の中に
「compile project(‘:openCVLibrary2410’)」を追加
Let`s OpenCV
Tools->Android->Sync Project with Gradle Filesを選択
Let`s OpenCV
プロジェクトにOpenCVの導入はこれで終了
https://github.com/Collonville/OpenCVTestApp/blob/master/app/src/main/java/com/example/collo
nville/opencvtestapp/MainActivity.java
今回は初期プロジェクトの行数が多いのでGithubから落としてきてください
Let`s OpenCV
「Androidmanifest.xml」でUser Permissionを設定する
セキュリティ上リスクを伴うもの(通信関係、プライバシー、etc)に関しては
ユーザーから許可を得ないと正常な動作が行われない(インストール時の契約)
デフォルトでは全機能に関して不許可が与えられ、
許可していないのに実行するとSecurityExceptionが投げられる
Let`s OpenCV
「activity_main.xml」でレイアウトの設定
取得した画像データはJavaCameraViewに表示される
Let`s OpenCV
実機で実行すると以下のように表示されましたか??
OpenCVで画像処理
Project1「カラー画像をグレースケールに変換するAPP」
#1 グレースケールAPP
R
G
B
Gray
RGB(8bit、チャンネル数:3)で1つのピクセルを表現
Gray(8bit、チャンネル数:1)で1つのピクセルを表現
#1 グレースケールAPP
R
G
B
Gray
RGBを白黒グレーに変換するアルゴリズム
・単純平均法
・NTSC系加重平均法
#1 グレースケールAPP
単純平均法
R,G,Bのそれぞれの値の平均をとる方法
𝑳𝒊,𝒋 =
𝑹𝒊,𝒋 + 𝑮𝒊,𝒋 + 𝑩𝒊,𝒋
𝟑
NTSC系加重平均法
R,G,Bに重みを付けてスケールをとる方法
𝑳𝒊,𝒋 = 𝟎. 𝟐𝟗𝟖𝟗𝟏𝟐 ∗ 𝑹𝒊,𝒋 + 𝟎. 𝟓𝟖𝟔𝟔𝟏𝟏 ∗ 𝑮𝒊,𝒋 + 𝟎. 𝟏𝟏𝟒𝟒𝟕𝟖 ∗ 𝑩𝒊,𝒋
人間は青のほうが暗く感じる->青色を優先的に暗く
単純平均法よりも自然なグレースケールが作れる
詳細はググってどうぞ
#1 グレースケールAPP
1.Matクラスのメンバー変数を作成
2.onCameraViewStarted()の中でオブジェクト作成
CvType.CV_8UC1 => 8bitのチャンネル1の画像
#1 グレースケールAPP
3.onCameraFrame()の中で毎フレームの処理を追加
cvtColor(const Mat& src, Mat& dst, int code, int dstCn=0)
指定した色空間に変換しdstに渡す
今回の処理
RGBAの色空間画像グレースケールの色空間画像
codeにImgproc.COLOR_RGBA2GRAYを使用
#1 グレースケールAPP
https://github.com/Collonville/GrayScaleApp
Project2「グレー画像を2値化するAPP」
2値化各ピクセルを任意の数値(2つ)に仕分ける作業
Let`s OpenCV
160 20 100 255
255 0 0 255
閾値150で0と255に2値化
1行追加するだけで完成・・・
#2 2値化APP
threshold(const Mat& src, Mat& dst, double thresh,
double maxVal, int thresholdType)
入力画像に対して閾値(thresh)で2値化させ
Typeに合わせてmaxValを代入する
#2 2値化APP
#2 2値化APP
Thresoldの様々なタイプ
Imgproc.THRESH_BINARYthresh以上はmaxVal。それ以外は0
𝑑𝑠𝑡 𝑖, 𝑗 =
𝑚𝑎𝑥𝑉𝑎𝑙 𝑖𝑓 𝑠𝑟𝑐 𝑖, 𝑗 > 𝑡ℎ𝑟𝑒𝑠ℎ
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Imgproc.THRESH_BINARY_INVthresh以上は0。それ以外はmaxVal
𝑑𝑠𝑡 𝑖, 𝑗 =
0 𝑖𝑓 𝑠𝑟𝑐 𝑖, 𝑗 > 𝑡ℎ𝑟𝑒𝑠ℎ
𝑚𝑎𝑥𝑉𝑎𝑙 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Imgproc.THRESH_TOZEROthresh以上はそのまま。それ以外は0
𝑑𝑠𝑡 𝑖, 𝑗 =
𝑠𝑟𝑐(𝑖, 𝑗) 𝑖𝑓 𝑠𝑟𝑐 𝑖, 𝑗 > 𝑡ℎ𝑟𝑒𝑠ℎ
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
#2 2値化APP
今のままだと、閾値を実行時に毎回確認しなければならない
↓
実行時でも閾値をいじって確認が
できるAPPが欲しい!!!
Project3「グレー画像を2値化するAPP改」
仕様:スライダーを使って閾値をいじれるようにする
#3 2値化APP改
Step1:Viewの追加
SeekBar*2、TextView*2、JavaCameraView*1(前のをコピペ)
Step2:ID、名前を指定
今回は各自自由に名前をつけてください
TextViewはandroid:textColor=“#FFFFFF”
で白色にすることをおすすめ
#3 2値化APP改
Step3:コードの実装
onCreate()の中でインスタンスをもらう。SeekBarの設定
setProgress(int)初期値の設定
setMax(int)SeekBarの最大値の設定
#3 2値化APP改
Step3:コードの実装
SeekBarリスナーの実装
#3 2値化APP改
Step3:コードの実装
閾値と最大値をthreshold()に反映
実装はこれで終了!!!
#3 2値化APP改
Step4:確認
閾値のみを変更させた時の様子
2値化APP改ver2
5つあるThresholdのTypeをボタンで選択できるようにする
#4 課題!!
Imgproc.THRESH_BINARY
Imgproc.THRESH_BINARY_INV
Imgproc.THRESH_TRUNC
Imgproc.TOZERO
Imgproc.TOZERO_INV
ボタンの作り方、コードを忘れた
前回の資料を見るかググって(# ゚Д゚)

More Related Content

Similar to 2015年度研究室プレ卒研用Android講座2

【Android勉強会】第一回Activity & intent
【Android勉強会】第一回Activity & intent【Android勉強会】第一回Activity & intent
【Android勉強会】第一回Activity & intentIshin FUKUOKA
 
デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発Kenta Ohsugi
 
OSC2011 Androidハンズオン
OSC2011 AndroidハンズオンOSC2011 Androidハンズオン
OSC2011 AndroidハンズオンKatsumi Honda
 
Pin-point rebuildable and non-rebuild custom widget
Pin-point rebuildable and non-rebuild custom widgetPin-point rebuildable and non-rebuild custom widget
Pin-point rebuildable and non-rebuild custom widgetcch-robo
 
Head First XML Layout on Android
Head First XML Layout on AndroidHead First XML Layout on Android
Head First XML Layout on AndroidYuki Anzai
 
Extending the Unity Editor Extended
Extending the Unity Editor ExtendedExtending the Unity Editor Extended
Extending the Unity Editor ExtendedMasamitsu Ishikawa
 
Unityの夕べ in Fukuoka
Unityの夕べ in FukuokaUnityの夕べ in Fukuoka
Unityの夕べ in FukuokaShinobu Izumi
 
iOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKitiOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKitShingo Hiraya
 
20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetinaKazuya Hirobe
 
CleanArchitecture with AssemblyDefinition in unity
CleanArchitecture with AssemblyDefinition in unityCleanArchitecture with AssemblyDefinition in unity
CleanArchitecture with AssemblyDefinition in unityNakanoYosuke1
 
よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかよこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかYuichiro Suzuki
 
Android UIデザイン入門
Android UIデザイン入門Android UIデザイン入門
Android UIデザイン入門OESF Education
 

Similar to 2015年度研究室プレ卒研用Android講座2 (15)

【Android勉強会】第一回Activity & intent
【Android勉強会】第一回Activity & intent【Android勉強会】第一回Activity & intent
【Android勉強会】第一回Activity & intent
 
デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発
 
Extending the Unity Editor
Extending the Unity EditorExtending the Unity Editor
Extending the Unity Editor
 
OSC2011 Androidハンズオン
OSC2011 AndroidハンズオンOSC2011 Androidハンズオン
OSC2011 Androidハンズオン
 
Pin-point rebuildable and non-rebuild custom widget
Pin-point rebuildable and non-rebuild custom widgetPin-point rebuildable and non-rebuild custom widget
Pin-point rebuildable and non-rebuild custom widget
 
React native
React nativeReact native
React native
 
Head First XML Layout on Android
Head First XML Layout on AndroidHead First XML Layout on Android
Head First XML Layout on Android
 
Extra view @ kyobashi.swift
Extra view @ kyobashi.swiftExtra view @ kyobashi.swift
Extra view @ kyobashi.swift
 
Extending the Unity Editor Extended
Extending the Unity Editor ExtendedExtending the Unity Editor Extended
Extending the Unity Editor Extended
 
Unityの夕べ in Fukuoka
Unityの夕べ in FukuokaUnityの夕べ in Fukuoka
Unityの夕べ in Fukuoka
 
iOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKitiOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKit
 
20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina
 
CleanArchitecture with AssemblyDefinition in unity
CleanArchitecture with AssemblyDefinition in unityCleanArchitecture with AssemblyDefinition in unity
CleanArchitecture with AssemblyDefinition in unity
 
よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているかよこへな3 15発表資料 最近ViewController をどんな感じで書いているか
よこへな3 15発表資料 最近ViewController をどんな感じで書いているか
 
Android UIデザイン入門
Android UIデザイン入門Android UIデザイン入門
Android UIデザイン入門
 

Recently uploaded

LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptxsn679259
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsWSO2
 

Recently uploaded (10)

LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 

2015年度研究室プレ卒研用Android講座2