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
620
ViewModel使ってますか?
katsukinakatani
0
300
デフォルトアプリとパーミッション
katsukinakatani
0
180
Target SDK Version 26に上げる時につまづいたこと
katsukinakatani
3
2.8k
Whats new android wear (umeda.apk #3 LT)
katsukinakatani
1
450
Android 7.1.1 AppShortcuts setup(DevfestKansai Lightning Talk)
katsukinakatani
1
650
Firebase Authentication & Firebase Realtime Database setup
katsukinakatani
2
830
Other Decks in Technology
See All in Technology
ハイテク休憩
sat
PRO
2
170
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
320
生成AIのガバナンスの全体像と現実解
fnifni
1
200
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
170
pg_bigmをRustで実装する(第50回PostgreSQLアンカンファレンス@オンライン 発表資料)
shinyakato_
0
100
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.3k
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
3
2.4k
UI State設計とテスト方針
rmakiyama
2
660
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
500
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
170
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Thoughts on Productivity
jonyablonski
67
4.4k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
How GitHub (no longer) Works
holman
311
140k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fireside Chat
paigeccino
34
3.1k
We Have a Design System, Now What?
morganepeng
51
7.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Optimising Largest Contentful Paint
csswizardry
33
3k
Designing Experiences People Love
moore
138
23k
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,Ͱ ͢
͓ർΕ༷Ͱͨ͠ɻ