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
Androidで触れてみようCloud Vision API_ハンズオン
Search
katsuki-nakatani
April 30, 2016
Technology
0
770
Androidで触れてみようCloud Vision API_ハンズオン
2016/4/30 GDG is a hands-on document of CloudVisionAPI in Kobe
katsuki-nakatani
April 30, 2016
Tweet
Share
More Decks by katsuki-nakatani
See All by katsuki-nakatani
Android 10 対応 Tips
katsukinakatani
0
83
InAppUpdate実装&InAppBillingClientVer2.0実装例
katsukinakatani
0
490
AndroidJetpack概要 &旧AACの紹介
katsukinakatani
0
610
ViewModel使ってますか?
katsukinakatani
0
300
デフォルトアプリとパーミッション
katsukinakatani
0
180
Target SDK Version 26に上げる時につまづいたこと
katsukinakatani
3
2.7k
Whats new android wear (umeda.apk #3 LT)
katsukinakatani
1
450
Android 7.1.1 AppShortcuts setup(DevfestKansai Lightning Talk)
katsukinakatani
1
640
Firebase Authentication & Firebase Realtime Database setup
katsukinakatani
2
820
Other Decks in Technology
See All in Technology
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
180
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
The Role of Developer Relations in AI Product Success.
giftojabu1
0
140
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
1k
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
200
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
150
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
100
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
230
Featured
See All Featured
Building Your Own Lightsaber
phodgson
103
6.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
A better future with KSS
kneath
238
17k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Adopting Sorbet at Scale
ufuk
73
9.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Site-Speed That Sticks
csswizardry
0
31
Building Adaptive Systems
keathley
38
2.3k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Happy Clients
brianwarren
98
6.7k
Transcript
$-06%7*4*0/"1* ϋϯζΦϯࢿྉ (%(,PCF $MPVE7JTJPO"QJ5FOTPSqPXษڧձ
͓͓·͔ͳྲྀΕ ̍ɽ$-06%7*4*0/"1*Λ༗ޮʹ͢Δ ̏ɽ"OESPJEʹɺ"1*ΞΫηε͢ΔͨΊͷΩʔΛΈࠐΉ ̐ɽ-BCFM%FUFDUJPOΛࢼͯ͠ΈΑ͏ʂ ̑ɽ'BDF%FUFDUJPOΛࢼͯ͠ΈΑ͏ʂ ̔ɽ͓·͚ ̎ɽ"OESPJEͷ࣮ߦڥΛ࡞Γ·͠ΐ͏ ̒ɽ5FYU%FUFDUJPOΛࢼͯ͠ΈΑ͏ʂ ̓ɽ4BGF4FBSDI%FUFDUJPOΛࢼͯ͠ΈΑ͏ʂ
̍ɽ$-06%7*4*0/"1*Λ༗ޮʹ͢Δ
(PPHMF"1*$POTPMFΞΫηε ϒϥβͰʮɹIUUQTDPOTPMFEFWFMPQFSTHPPHMFDPN IM+"ɹʯΞΫηε͍ͯͩ͘͠͞
(PPHMF"1*$POTPMF ͜͜ΛΫϦοΫ͍ͯͩ͘͠͞
ϓϩδΣΫτͷ࡞ ϓϩδΣΫτͷ࡞ΛΫϦοΫ͠·͢
ϓϩδΣΫτͷ࡞ ϓϩδΣΫτ໊ΛܾΊͯ ར༻نʹಉҙͯ͠ ࡞͠·͢ ˞ॳΊͯϓϩδΣΫτΛ࡞ΔਓҎ֎গ͠ը໘͕ҧ͏ͱࢥ͍·͕͢ɺಉ༷ʹ࡞·ͰਐΜͰ͍ͩ͘͞
ϓϩδΣΫτͷ࡞ྃ ͘Δ͘Δ࡞ۀத ྃͯ͠ϓϩδΣΫτ͕બ͞Εͨ ঢ়ଶʹͳΓ·͢
$-06%7*4*0/"1*Λ༗ޮʹ͠·͠ΐ͏ $MPVE7JTJPOͱೖྗ͠·͠ΐ͏ ϑΟϧλ͕͔͔ͬͯදࣔ͞Ε·͢ ΫϦοΫ͠·͠ΐ͏
$-06%7*4*0/"1*Λ༗ޮʹ͠·͠ΐ͏ ΫϦοΫ͠·͢
ٻઌొΛ͠·͢ ٻઌΞΧϯτ͕ͳ͍߹ ΫϦοΫ͠·͢ $MPVE7JTJPO"1JҰఆྔΛ͑Δͱ՝͕͔͔ۚΔͨΊɺ՝ۚใΛొ͢Δඞཁ͕͋Γ·͢ ΫϦοΫ͠·͢
ొ ΫϦοΫ͠·͢ ඞཁͳใΛೖྗ͠·͢
ొྃ ΫϦοΫ͠·͢
$-06%7*4*0/"1*͕༗ޮʹͳΓ·ͨ͠ ΫϦοΫ͠·͢
"1*ΩʔΛൃߦ͠·͠ΐ͏ "1*ΩʔΛΫϦοΫ͠
"1*ΩʔΛൃߦ͠·͠ΐ͏ "1*Ωʔͷ໊લΛܾΊͯ ࡞
"1*Ωʔͷൃߦ͕ྃ͠·ͨ͠ Ωʔ͕ग़དྷͨͷͰ "1*ΩʔΛίϐʔͯ͠0,͠·͠ΐ͏
̎ɽ"OESPJEͷ࣮ߦڥΛ࡞Γ·͠ΐ͏
"OESPJE4UVEJPΛىಈ͍ͯͩ͘͠͞ *NQPSUQSPKFDUΛ ΫϦοΫ͠·͢ 8JOEPXTӈΫϦοΫͯ͠ཧऀͰ࣮ߦͰىಈ͍ͯͩ͘͠͞
ϓϩδΣΫτΛΠϯϙʔτ͠·͢ μϯϩʔυͯ͠ղౚͨ͠σΟϨΫτϦͷ @-BCFM%FUFDUJPOͷ$MPVE7JTJPO)BOETPOσΟϨΫτϦΛࢦఆ͠·͢ ґଘϥΠϒϥϦͳͲμϯϩʔυ͞Ε·͢ͷͰOFUXPSLʹܨ͍ͩঢ়ଶͰΠϯϙʔτ͍ͯͩ͘͠͞
"OESPJEQBUIͷΤϥʔ͕ग़ͨ߹ 0,Ͱదਖ਼ͳϩέʔγϣϯʹͯ͘͠ΕΔͣ ͘͜͜͠Λࣗͷ4%,ͷύεʹ͠·͢
KBWBWFSTJPOͷΤϥʔ͕ӈ্ʹग़ͨ߹ ΫϦοΫͯࣗ͠ͷڥʹ߹Θ͍ͤͯͩ͘͞
ϓϥάΠϯͷΠϯετʔϧ ϓϩδΣΫτͰMPNCPLϓϥάΠϯͬͯΔͷͰϓϥάΠϯೖΕ·͠ΐ͏ 1SFGFSFODFTΛΫϦοΫ #SPXTFSFQPTJUPSJFTΛΫϦοΫ 8JOEPXTͩͱ4FUUJOHT
MPNCPLͰݕࡧͯ͠*OTUBMMΛΫϦοΫ 3FTUBSUΛΫϦοΫͯ͠ "OESPJE4UVEJPΛ࠶ىಈ͠·͢
·࣮ͣػͷํ͔Βઆ໌͠·͢
Λ64#έʔϒϧͰɺ1$ʹଓ͍ͯͩ͘͠͞
ઃఆ͔ΒใΛ։͍ͯɺϏϧυ൪߸Λ࿈ଧ ͠·͢
Ұͭલͷը໘͔Βɺ։ൃऀ͚ΦϓγϣϯΛ։ ͖·͢ 64#σόοάΛ0/ʹ͠·͢ ϑΟϯΨʔϓϦϯτͷڐՄը໘͕ग़ ͨΒνΣοΫΛೖΕͯ0,Λԡ͠·͢
֬ೝ Լ෦ͷ"OESPJE.POJUPSΛ։͖·͢ ࣗͷ͕දࣔ͞ΕΔ͜ͱΛ֬ೝ͠·͢
ΤϛϡϨʔλͷ߹
4%,.BOBHFSΛ։͖·͢ 4%,5PPMTλϒͷ*OUFMY&NVMBUPSʜ ʹνΣοΫΛೖΕɺ"QQMZΛԡ͠·͢ ͳΜ͔ฉ͍ͯ͘ΔͷͰ0, ΛΫϦοΫ͠·͢
"DDFQUͯ͠/FYU͠·͠ΐ͏ )"9.Ͱ͏."9ϝϞϦͷࢦఆʁ ଟͦͷ··Ͱ/FYUͰ͍͍Ͱ͢ %POFͨ͠Β'JOJTIͯ͠શ෦ͷμΠΞϩάΛ ด͍͖ͯ͡·͠ΐ͏
"7%.BOBHFSΛ։͖·͢ $SFBUF7JSUVBM%FWJDFΛ ΫϦοΫ͠·͢
దʹػछΛબͼ·͠ΐ͏ /FYU
༻͢Δ04ͷόʔδϣϯΛબͼ·͢ /FYU ՄೳͰ͋ΕɺYΠϝʔδλϒͷɺY@ ͘͠YΛબ͍ͯͩ͘͠͞ "1*-FWFMҎ্ͷͷΛࢦఆ͍ͯͩ͘͠͞
4IPX"EWBODFE4FUUJOHTΛΫϦοΫ͠·͢ ΧϝϥΛઃఆ͠·͠ΐ͏ɻ ."$ͩͱ8FCDBN͕'BDU5JNFͷΧϝϥͰ͢
͏ͪΐͬͱεΫϩʔϧͯ͠ɺ4UPSBHFͷ༰ྔ Λ.#ʹ͠·͢ 'JOJTIͰ࡞Γ·͢ ग़དྷ·ͨ͠ɻ
ࡾ֯Ͱىಈ͠·͠ΐ͏ ӳޠͳΜͰɺຊޠʹ͠·͠ΐ͏ɻ ˞ӳޠ͕͍͍ਓͦͷ··ʹ͓͍͍ͯͯͩ͘͠͞ ϗʔϜϘλϯ "OESPJE4UVEJPҎ্Ͱ͋ΔͳΒΘΓͱૣ͘ىಈͯ͘͠ΔͣͰ͢ɻ 4FUUJOHT -BOHVBHF*OQVU -BOHVBHFͰຊޠΛબͼ·͢
ͷ४උ0,Ͱ͢
ϏϧυΛͯ͠ΈΑ͏
͜ΕΛΫϦοΫͯ͠HSBEMFϏϧυ͠·͢ ৭ʑڥҧ͏ͱΤϥʔ͕ग़Δ CVJMEHSBEMF .PEVMFBQQ BOESPJE\ DPNQJMF4EL7FSTJPO CVJME5PPMT7FSTJPȌ EFGBVMU$POpH\ BQQMJDBUJPO*EPSHHEHLPCFFYBNQMFDMPVEWJTJPO NJO4EL7FSTJPO
UBSHFU4EL7FSTJPO WFSTJPO$PEF WFSTJPO/BNF ^ CVJME5ZQFT\ SFMFBTF\ NJOJGZ&OBCMFEGBMTF QSPHVBSE'JMFTHFU%FGBVMU1SPHVBSE'JMF QSPHVBSEBOESPJEUYU QSPHVBSESVMFTQSP ^ ^ ^ ͜͜ΒΜʁ
.FTTBHFλϒΛΫϦοΫͯ͠46$$&44'6-ʹͳͬͯͨΒ0, ࣮ߦͯ͠Έ·͠ΐ͏ બΜͰ0,
͜͜·Ͱ͍͚0,Ͱ͢
̏ɽ"OESPJEʹɺ"1*ΞΫηε͢ΔͨΊͷΩʔ ΛΈࠐΉ
1SPKFDUʹ"1*ΩʔΛΈࠐΈ·͢ ࠨπϦʔϏϡʔͷதʹSFTσΟϨΫτϦ͕͋ΔͷͰɺSFTWBMVFTͷதʹ͋ΔHPPHMF@BQJ@LFZYNMΛ։͖·͢ ͜͜ͷ:063@"1*@,&:Λஔ͖͑·͠ΐ͏ɻ
ɽ-BCFM%FUFDUJPOΛࢼͯ͠ΈΑ͏
-BCFM%FUFDUJPOͷϑΥʔϚοτΛݟͯΈ·͠ΐ͏ 3FRVFTUଆ "OOPUBUF*NBHF3FRVFTUͱ͍͏ύϥϝʔλΛෳͤ·͢ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF JNBHFͱGFBUVSFT ෳ ͱJNBHF$POUFYU͕ͤ·͢ DPOUFOU จࣈྻ ͱTPVSDFͱ͍͏ΦϒδΣΫτΛ͢͜ͱ͕ग़དྷΔΑ͏Ͱ͢
TPVSDFͱ͍͏ͷɺ(PPHMF$MPVE4UPSBHFͷը૾ͷॴΛࢦఆ͢ΔύϥϝʔλͳͷͰࠓճεϧʔ͠·͢ ࠓճDPOUFOUͰը૾Λ͠·͢
-BCFM%FUFDUJPOͷϑΥʔϚοτΛݟͯΈ·͠ΐ͏ 3FRVFTUଆ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF GFBUVSFTʹUZQF ղੳ͍ͨ͠λΠϓ ͱNBY3FTVMUT ࠷େ݁Ռ Λ͠·͢ ྫ͑Ͱ͕͢ɺମݕͱإݕ྆ํΛಉ͡ը૾ʹରͯ͠ߦ͍͍ͨ߹ɺ ͜ͷΑ͏ͳσʔλΛ࡞͢ΔΠϝʔδʹͳΓ·͢
'FBUVSF -"#&-@%&5&$5*0/ 'FBUVSF '"$&@%&5&$5*0/ KBWBPSHHEHLPCFFYBNQMFDMPVEWJTJPOFOUJUZʹಉ༷ͷ໊લͰఆٛΛ͍ͯ͠·͢ ཁԿΛ͍͍͔ͤͱ͍͏ͱ ɹը૾σʔλ ɹ ݕ͍ͨ͠λΠϓ ɹ݁Ռͱͯ͠΄͍͠࠷େ݅ Y/ ͜ΕΛͤ0,Ͱ͢
-BCFM%FUFDUJPOͷϑΥʔϚοτΛݟͯΈ·͠ΐ͏ 3FTQPOTFଆ "OOPUBUF*NBHF3FTQPOTFͱ͍͏ύϥϝʔλ͕ෳฦͬͯདྷ·͢ɻ ʢϦΫΤετͰ͚͛ͨͩʣ &OUJUZ"OOPUBUJPOͱهࡌ͕͋Γ·͕͢-BCFM%FUFDUJPOͰ ؼͬͯ͘Δͷɺ NJE *% ͱEFTDSJQUJPO ༰
ͱTDPSF ৴པ ͚ͩͰ͢
ϦΫΤετͯ͠ΈΑ͏
"1*ͷϦΫΤετఆٛ QVCMJDJOUFSGBDF7JTJPO"QJ\ !)FBEFST $POUFOU5ZQFBQQMJDBUJPOKTPO !1045 WJNBHFTBOOPUBUF $BMM3FTQPOTFQPTU !2VFSZ
LFZ 4USJOH"QJ,FZ !#PEZ3FRVFTUSFRVFTU ^ KBWBPSHHEHLPCFFYBNQMFDMPVEWJTJPOBQJ7JTJPO"QJΛ։͖·͢ ࣮ࡍͷSFRVFTUԼهͷΑ͏ͳ63-ʹͳΓ·͢ IUUQTWJTJPOHPPHMFBQJTDPNWJNBHFTBOOPUBUF LFZ:063,&:
Ϩεϙϯε༻ͷΫϥεΛ࡞͠·͢ KBWBPSHHEHLPCFFYBNQMFDMPVEWJTJPOFOUJUZΛӈΫϦοΫͯ͠ɺOFX+BWB$MBTTΛ৽ن࡞͠·͢ Ϋϥεʹඞཁͳύϥϝʔλͱ"OOPUBUJPOΛ͚ͭ·͢ !%BUB !/P"SHT$POTUSVDUPS QVCMJDDMBTT-BCFM"OOPUBUJPO\ QSJWBUF4USJOHNJE QSJWBUF4USJOHEFTDSJQUJPO QSJWBUFqPBUTDPSF ^
Ϩεϙϯεͷதʹ-BCFM"OOPUBUJPOͷఆٛΛՃ͠·͢ KBWBPSHHEHLPCFFYBNQMFDMPVEWJTJPOFOUJUZ"OOPUBUF3FTQPOTFΛฤू͠ɺ-JTU-BCFM"OOPUBUJPOͷΓΛه͠·͢ !%BUB !/P"SHT$POTUSVDUPS QVCMJDDMBTT"OOPUBUF3FTQPOTF\ QSJWBUF-JTU'BDF"OOPUBUJPOGBDF"OOPUBUJPOTOFX"SSBZ-JTU QSJWBUF-JTU5FYU"OOPUBUJPOUFYU"OOPUBUJPOTOFX"SSBZ-JTU
QSJWBUF-JTU-BCFM"OOPUBUJPOMBCFM"OOPUBUJPOTOFX"SSBZ-JTU ^
$BMM͢Δը໘ͷॲཧΛɺॻ͍͍͖ͯ·͢ ฤू͢Δͷɺ-BCFM%FUFDUJPO"DUJWJUZͷϑΝΠϧͰ͢ ༧ΊΧϝϥ͔ΒͷࡱӨΪϟϥϦʔ͔Βͷݺͼग़࣮͠ࡁΈͰ͕͢ɺ Լه͕࣮͞Ε͍ͯ·ͤΜ ࣸਅΛબͨ͠ޙͷ$MPVE7JTJPO"1*ͷίʔϧॲཧ "1*ίʔϧޙʹɺ݁ՌͷใΛը໘ʹηοτ͢Δॲཧ WPJEDBMM$MPVE7JTJPO WPJETFU5FYU -JTU-BCFM"OOPUBUJPOMBCFM"OOPUBUJPOT
"1*ίʔϧॲཧΛॻ͖·͠ΐ͏ DBMM$MPVE7JTJPO ͷϝιουͷɺ#JUNBQͷ/VMMνΣοΫ͕ऴΘͬͨͱ͜Ζʹه͠·͢ //HttpClientͷੜ OkHttpClient client = new OkHttpClient.Builder(). addInterceptor(new
JsonInterceptor()). build(); // RetrofitAdapterͷੜ Retrofit adapter = new Retrofit.Builder() .baseUrl(API_BASE_URL) .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .client(client) .build(); // ඇಉظॲཧͷ࣮ߦ Request request = new Request(); request.addRequest(mBitmap, new Feature(Feature.FeatureType.LABEL_DETECTION)); adapter.create(VisionApi.class).post(getString(R.string.vision_api), request) .enqueue(new Callback<Response>() { @Override public void onResponse(Call<Response> call, retrofit2.Response<Response> response) { if (response.body().getResponses().get(0).getLabelAnnotations().size() <= 0) { Snackbar.make(mCoordinator, R.string.label_annotation_error, Snackbar.LENGTH_LONG).show(); } else { mOriginalJson = response.message(); } } @Override public void onFailure(Call<Response> call, Throwable t) { } }); Snackbar.make(mCoordinator, R.string.vision_api_upload, Snackbar.LENGTH_LONG).show(); 3FRVFTUͱ3FTQPOTFΠϯϙʔτީิ͕ෳ͋ΔͨΊ"MU &OUFSͰϓϩδΣΫτ෦ͷΛΠϯϙʔτ͍ͯͩ͘͠͞ $BMM#BDLෳީิ͕͋ΔͷͰɺͪ͜ΒSFUSPpUͷͷΛΠϯϙʔτ͍ͯͩ͘͠͞
݁ՌͷηοτॲཧΛॻ͖·͠ΐ͏ ৽نͰϝιουΛ࡞͠·͢ void setText(List<LabelAnnotation> labelAnnotations) { StringBuilder stringBuilder = new
StringBuilder(); for (LabelAnnotation labelAnnotation : labelAnnotations) { stringBuilder.append(getString(R.string.label_detection_result, labelAnnotation.getDescription(), labelAnnotation.getScore() * 100)); } mTextView.setText(stringBuilder.toString()); } adapter.create(VisionApi.class).post(getString(R.string.vision_api), request) .enqueue(new Callback<Response>() { @Override public void onResponse(Call<Response> call, retrofit2.Response<Response> response) { if (response.body().getResponses().get(0).getLabelAnnotations().size() <= 0) { Snackbar.make(mCoordinator, R.string.label_annotation_error, Snackbar.LENGTH_LONG).show(); } else { mOriginalJson = response.message(); ɹɹɹɹsetText(response.body().getResponses().get(0).getLabelAnnotations()); } } @Override public void onFailure(Call<Response> call, Throwable t) { } }); Snackbar.make(mCoordinator, R.string.vision_api_upload, Snackbar.LENGTH_LONG).show(); MBCFM"OOPUBUJPOT͕̍݅Ͱ͋ͬͨ߹4FU5FYUΛݺͼग़ͯ͠දࣔ͢ΔΑ͏ʹ͠·͠ΐ͏
࣮ߦͯ͠Έ·͠ΐ͏
̑ɽ'BDF%FUFDUJPOΛࢼͯ͠ΈΑ͏
'BDF%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ 3FTQPOTFଆ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF ݕग़ͨ͠إશମͷΤϦΞͱɺݕग़ͨ͠ൽෘͷΤϦΞͷΛද͠·͢ 7FSUFY<> 7FSUFY<> 7FSUFY<> 7FSUFY<>
'BDF%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ 3FTQPOTFଆ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF ݕग़ͨ͠إͷ֤ύʔπͷใϦετͰ͢
'BDF%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF ύϯͱϩʔϧͱνϧτɻ إ͕Ͳ͜Λ͍͍ͯΔͷ͔ΛճసใͰද͠·͢
'BDF%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF إೝࣝࣗମͷ৴པੑ EFUFDUJPO$POpEFODF ͱ ֤ύʔπͷ৴པੑ MBOENBSLJOH$POpEFODF Λද͠·͢
'BDF%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ IUUQTDMPVEHPPHMFDPNWJTJPOSFGFSFODFSFTUWJNBHFTBOOPUBUF ײΛ̑ஈ֊Ͱද͠·͢ KPZ-JLF ɹָ͠ΜͰ͍Δ͔ TPSSPX-JLF ɹ൵͠ΜͰ͍Δ͔ BOHFS-JLF ɹౖ͍ͬͯΔ͔ TVSQSJTF-JLF
ɹڻ͍͍ͯΔ͔ VOEFS&YQPTFE-JLF ɹ࿐ޫෆʁ CMVSSFE-JLF ɹ΅͚ͯΔʁ IFBEXFBS-JLF ɹͳΜ͔͔ͿͬͯΔ
-BCFM%FUFDUJPOͱಉ༷ʹ$BMM͢ΔϓϩάϥϜΛॻ͍͍͖ͯ·͢ ฤू͢Δͷɺ'BDF%FUFDUJPO"DUJWJUZͷϑΝΠϧͰ͢ ࣸਅΛબͨ͠ޙͷ$MPVE7JTJPO"1*ͷίʔϧॲཧ "1*ίʔϧޙʹɺ݁ՌͷใΛը໘ʹηοτ͢Δॲཧ WPJEDBMM$MPVE7JTJPO WPJETIPX'BDF%FUFDUJPO'SBHNFOU 4USJOHKTPO
"1*ίʔϧॲཧΛॻ͖·͠ΐ͏ DBMM$MPVE7JTJPO ͷϝιουͷɺ#JUNBQͷ/VMMνΣοΫ͕ऴΘͬͨͱ͜Ζʹه͠·͢ //HttpClientͷੜ OkHttpClient client = new OkHttpClient.Builder(). addInterceptor(new
JsonInterceptor()). build(); // RetrofitAdapterͷੜ Retrofit adapter = new Retrofit.Builder() .baseUrl(API_BASE_URL) .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .client(client) .build(); // ඇಉظॲཧͷ࣮ߦ Request request = new Request(); request.addRequest(mBitmap, new Feature(Feature.FeatureType.FACE_DETECTION)); adapter.create(VisionApi.class).post(getString(R.string.vision_api), request) .enqueue(new Callback<Response>() { @Override public void onResponse(Call<Response> call, retrofit2.Response<Response> response) { if (response.body().getResponses().get(0).getFaceAnnotations().size() <= 0) { Snackbar.make(mCoordinator, R.string.face_annotation_error, Snackbar.LENGTH_LONG).show(); } else { mOriginalJson = response.message(); } } @Override public void onFailure(Call<Response> call, Throwable t) { } }); Snackbar.make(mCoordinator, R.string.vision_api_upload, Snackbar.LENGTH_LONG).show();
݁ՌͷηοτॲཧΛॻ͖·͠ΐ͏ ࠓճ'SBHNFOUʹΛ͢Α͏ʹ͍ͯ͠·͢ ৽نͰϝιουΛ࡞͠·͢ void showFaceDetectionFragment(String json) { Fragment f =
getSupportFragmentManager().findFragmentById(R.id.fragment); if (f instanceof FaceDetectionFragment) { ((FaceDetectionFragment) f).update(json); } else { getSupportFragmentManager(). beginTransaction() .replace(R.id.fragment, FaceDetectionFragment.newInstance(json)) .commitAllowingStateLoss(); } } adapter.create(VisionApi.class).post(getString(R.string.vision_api), request) .enqueue(new Callback<Response>() { @Override public void onResponse(Call<Response> call, retrofit2.Response<Response> response) { if (response.body().getResponses().get(0).getFaceAnnotations().size() <= 0) { Snackbar.make(mCoordinator, R.string.face_annotation_error, Snackbar.LENGTH_LONG).show(); } else { mOriginalJson = response.message(); showFaceDetectionFragment(response.message()); } } @Override public void onFailure(Call<Response> call, Throwable t) { } }); Snackbar.make(mCoordinator, R.string.vision_api_upload, Snackbar.LENGTH_LONG).show(); 'BDF"OOPUBUJPOT͕̍݅Ͱ͋ͬͨ߹'SBHNFOUΛηοτͯ͠දࣔ͢ΔΑ͏ʹ͠·͠ΐ͏
࣮ߦͯ͠Έ·͠ΐ͏
ೝࣝͰ͖͚ͨͲɺ࠲ඪͬͯຊʹਖ਼͍͠ʁ ͜͏͍͏Λදࣔͯ֬͠ೝ͍ͨ͠
࣮ࡍฦͬͯདྷͨ࠲ඪΛදࣔͯ͠ΈΑ͏
"DUJWJUZଆʹ࠲ඪදࣔ༻ͷϝιουΛΈࠐΈ·͠ΐ͏ ࣄલʹJOUFSGBDFΛ࡞͍ͯ͠ΔͷͰͦΕΛ࣮͠·͢ ฤू͢Δͷ'BDF%FUFDUJPO"DUJWJUZͰ͢ "DUJWJUZʹ·ͣJNQMFNFOUT͠·͠ΐ͏ QVCMJDDMBTT'BDF%FUFDUJPO"DUJWJUZFYUFOET7JTJPO#BTF"DUJWJUZJNQMFNFOUT*NBHF6QEBUF-JTUFOFS //ύʔπݕग़ΤϦΞͷϘʔμʔΧϥʔ private static final int
LANDMARK_AREA_COLOR = Color.argb(255, 255, 255, 255); //إݕग़ΤϦΞͷϘʔμʔΧϥʔ private static final int POLY_AREA_COLOR = Color.argb(255, 255, 0, 0); //ύʔπݕग़ΤϦΞͷΤϦΞαΠζ private static final int LANDMARK_AREA_SIZE = 10; ઢඳը༻ͷύϥϝʔλΛઌʹఆ͓͖ٛͯ͠·͢ *NBHF6QEBUF-JTUFOFSʹΧʔιϧΛͯͯ"MU &OUFSͰ*NQMFNFOUNFUIPETΛల։Ͱ͖·͢
ઢΛඳը͢ΔϝιουΛΈࠐΈ·͠ΐ͏ -BOENBSL إͷύʔπ ͷॴΛදࣔ͠·͢ !0WFSSJEF QVCMJDWPJETFU1PJOU qPBUY qPBUZ \ $BOWBTDBOWBT
#JUNBQOFX#JUNBQ#JUNBQDSFBUF#JUNBQ N#JUNBQHFU8JEUI N#JUNBQHFU)FJHIU #JUNBQ$POpH"3(#@ DBOWBTOFX$BOWBT OFX#JUNBQ DBOWBTESBX#JUNBQ N#JUNBQ OVMM 1BJOUQBJOUOFX1BJOU QBJOUTFU$PMPS -"/%."3,@"3&"@$0-03 QBJOUTFU4UZMF 1BJOU4UZMF4530,& QBJOUTFU4USPLF8JEUI DBOWBTESBX3FDU Y-"/%."3,@"3&"@4*;& Z-"/%."3,@"3&"@4*;& Y -"/%."3,@"3&"@4*;& Z -"/%."3,@"3&"@4*;& QBJOU N*NBHFTFU*NBHF#JUNBQ OFX#JUNBQ DPMMBQTF#PUUPN4IFFU ^ ̎ ̍ ̏ ̐ ̍ɽΩϟϯόεʹ·ͣΞοϓϩʔυͨ͠ը૾Λඳը͍ͯ͠·͢ ̎ɽΩϟϯόεʹՃͰॻ͘ϒϥγͷఆٛΛ͍ͯ͠·͢ ࣄલʹఆٛͨ͠$0-03Λར༻͢ΔΑ͏ʹ͍ͯ͠·͢ ̏ɽ࢛֯Λඳը͍ͯ͠·͢ɹ࢛۱ͷϙΠϯτΛࢦఆ͍ͯ͠ΔͨΊɺΒͬͨҐஔΛʹͯ͠͠Ҿ͖࢛ͯ͠۱Λࢦఆ͍ͯ͠·͢ ̐ɽඳ͍ͨ#JUNBQΛը໘ͷ*NBHF7JFXʹηοτ͍ͯ͠·͢
ઢΛඳը͢ΔϝιουΛΈࠐΈ·͠ΐ͏ CPVOEJOH1PMZ ݕग़ͨ͠إͷΤϦΞ ͷॴΛදࣔ͠·͢ !0WFSSJEF QVCMJDWPJETFU1PMZ 1PMZCPVOEJOH1PMZ 1PMZGC#PVOEJOH1PMZ \ $BOWBTDBOWBT
#JUNBQOFX#JUNBQ#JUNBQDSFBUF#JUNBQ N#JUNBQHFU8JEUI N#JUNBQHFU)FJHIU #JUNBQ$POpH"3(#@ DBOWBTOFX$BOWBT OFX#JUNBQ DBOWBTESBX#JUNBQ N#JUNBQ OVMM 1BJOUQBJOUOFX1BJOU QBJOUTFU$PMPS 10-:@"3&"@$0-03 QBJOUTFU4UZMF 1BJOU4UZMF4530,& QBJOUTFU4USPLF8JEUI DBOWBTESBX3FDU CPVOEJOH1PMZHFU7FSUJDFT HFU HFU9 CPVOEJOH1PMZHFU7FSUJDFT HFU HFU: CPVOEJOH1PMZHFU7FSUJDFT HFU HFU9 CPVOEJOH1PMZHFU7FSUJDFT HFU HFU: QBJOU DBOWBTESBX3FDU GC#PVOEJOH1PMZHFU7FSUJDFT HFU HFU9 GC#PVOEJOH1PMZHFU7FSUJDFT HFU HFU: GC#PVOEJOH1PMZHFU7FSUJDFT HFU HFU9 GC#PVOEJOH1PMZHFU7FSUJDFT HFU HFU: QBJOU N*NBHFTFU*NBHF#JUNBQ OFX#JUNBQ ^ 1PMZܕɺ࢛۱ͷใΛ͍ͯ࣋ͬͯ͢ ΔͷͰɺࠨ্ͱӈԼͷ࠲ඪΛऔΓग़ͯ͠ࢦ ఆ͍ͯ͠·͢
࣮ߦͯ͠ΈΑ͏
Ͳ͏Ͱ͠ΐ͏͔ʁ $MPVE7JTJPO"1*ͷਫ਼ͷߴ͕࣮͞ײͰ͖ΔͷͰ ͳ͍͔ͱࢥ͍·͢
̒ɽ5FYU%FUFDUJPOΛࢼͯ͠ΈΑ͏
5FYU%FUFDUJPOͷϨεϙϯεϑΥʔϚοτΛݟͯΈ·͠ΐ͏ ͜Ε͕ϦετͰฦͬͯདྷ·͢ NJE *% MPDBMF ղੳͨ͠ݴޠ EFTDSJQUJPO ղੳ݁Ռͷจࣈྻ
TDPSF ৴པ CPVOEJOH1PMZ ղੳͨ͠ΤϦΞͷใ QSJWBUF4USJOHNJE QSJWBUF4USJOHMPDBMF QSJWBUF4USJOHEFTDSJQUJPO QSJWBUFqPBUTDPSF QSJWBUF1PMZCPVOEJOH1PMZ 5FYU"OOPUBUJPOKBWB
5FYU%FUFDUJPO"DUJWJUZΛฤू͠·͢ DBMM$MPVE7JTJPO ͷϝιουͷɺ#JUNBQͷ/VMMνΣοΫ͕ऴΘͬͨͱ͜Ζʹه͠·͢ʢ͏ҰॹͰ͢Ͷɻɻɻʣ //HttpClientͷੜ OkHttpClient client = new OkHttpClient.Builder(). addInterceptor(new
JsonInterceptor()). build(); // RetrofitAdapterͷੜ Retrofit adapter = new Retrofit.Builder() .baseUrl(API_BASE_URL) .addConverterFactory(MoshiConverterFactory.create(new Moshi.Builder().build())) .client(client) .build(); // ඇಉظॲཧͷ࣮ߦ Request request = new Request(); request.addRequest(mBitmap, new Feature(Feature.FeatureType.TEXT_DETECTION)); adapter.create(VisionApi.class).post(getString(R.string.vision_api), request) .enqueue(new Callback<Response>() { @Override public void onResponse(Call<Response> call, retrofit2.Response<Response> response) { if (response.body().getResponses().get(0).getTextAnnotations().size() <= 0) { Snackbar.make(mCoordinator, R.string.text_annotation_error, Snackbar.LENGTH_LONG).show(); } else { mOriginalJson = response.message(); showResult(); } } @Override public void onFailure(Call<Response> call, Throwable t) { } }); Snackbar.make(mCoordinator, R.string.vision_api_upload, Snackbar.LENGTH_LONG).show();
݁ՌΛηοτ͠Α͏ TIPX3FTVMU ͷϝιουʹ݁ՌΛදࣔ͢ΔΑ͏ʹ͠·͠ΐ͏ 5FYU%FUFDUJPOɺೝࣝͨ͠ΤϦΞใฦͬͯདྷ·͢ͷͰɺฦͬͯདྷͨςΩετͱɺઢΛ྆ํηοτ͍ͯ͠·͢ void showResult() { parse(); if (mResponse
!= null) { mLanguage.setText(mResponse.getResponses().get(0).getTextAnnotations().get(0).getLocale()); mResultText.setText(mResponse.getResponses().get(0).getTextAnnotations().get(0).getDescription()); List<Vertex> vertexList = mResponse.getResponses().get(0).getTextAnnotations().get(0).getBoundingPoly().getVertices(); Canvas canvas; Bitmap newBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888); canvas = new Canvas(newBitmap); canvas.drawBitmap(mBitmap, 0, 0, null); Paint paint = new Paint(); paint.setColor(POLY_AREA_COLOR); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(2); canvas.drawRect(vertexList.get(0).getX(), vertexList.get(0).getY(), vertexList.get(2).getX(), vertexList.get(2).getY() , paint); mImage.setImageBitmap(newBitmap); } }
̓ɽ4BGF4FBSDIΛࢼͯ͠ΈΑ͏
4BGF4FBSDI"OOPUBUJPOϑΥʔϚοτΛݟͯΈ·͠ΐ͏ ͜ΕϦετͰฦͬͯདྷ·ͤΜ Τϩ ҩྍ ྗ ͷΛ̑ஈ֊ͰධՁͯ͠ฦͯ͘͠Ε·͢
"OOPUBUF3FTQPOTFΛฤू͠·͢ ϨεϙϯεʹTBGF4FBSDI"OOPUBUJPOͷఆٛΛՃ͠·͢ public class AnnotateResponse { private List<FaceAnnotation> faceAnnotations =
new ArrayList<>(); private List<TextAnnotation> textAnnotations = new ArrayList<>(); private List<LabelAnnotation> labelAnnotations = new ArrayList<>(); private SafeSearchAnnotation safeSearchAnnotation; }
݁ՌΛηοτ͠Α͏ 4BGF4FBSDI%FUFDUJPO"DUJWJUZͷTIPX3FTVMU ͷϝιουʹ݁ՌΛදࣔ͢ΔΑ͏ʹ͠·͠ΐ͏ void showResult() { parse(); if (mResponse !=
null) { SafeSearchAnnotation annotation = mResponse.getResponses().get(0).getSafeSearchAnnotation(); mAdult.setRating(annotation.getRating(annotation.getAdult())); mSpoof.setRating(annotation.getRating(annotation.getSpoof())); mMedical.setRating(annotation.getRating(annotation.getMedical())); mViolence.setRating(annotation.getRating(annotation.getViolence())); mAdult.setText(getString(R.string.adult)); mSpoof.setText(getString(R.string.spoof)); mMedical.setText(getString(R.string.medical)); mViolence.setText(getString(R.string.violence)); } }
͓·͚
օ͞ΜɺϋϯζΦϯͷ࠷ޙ সإͰऴΘΓ·͠ΐ͏ʂ
+PZ5XFFU"DUJWJUZͷಈ͖ $MPVE7JTJPO"1* 'BDF%FUFDUJPO ָ͠ΜͰ͍Δ KPZ ύϥϝʔλ͕7&3:@-*,&-:͔ఆ 0, "[VSF8FC"QQ 5XFFU ϋϯζΦϯऴྃͰ͢
ࣸਅΛΞοϓ͍͍ͯ͠ͱ͍͏ਓνΣοΫΛ0/ʹ͍ͯͩ͘͠͞ χοΫωʔϜʹࣗͷTDSFFOOBNFΛೖΕΔͱɻࣗʹϝϯγϣϯདྷ·͢ !HEHLPCF@WJTJPOΈ͍ͨͳ 5XJUUFSͬͯͳ͍ਓదͳχοΫωʔϜͰ0,Ͱ ͢
͓ർΕ༷Ͱͨ͠ɻ