Nuke Olaf - Log Store

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - natario1/CameraView ์นด๋ฉ”๋ผ ํ•„ํ„ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ถ„์„ ๋ณธ๋ฌธ

Android

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - natario1/CameraView ์นด๋ฉ”๋ผ ํ•„ํ„ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ถ„์„

NukeOlaf 2020. 1. 4. 16:29

https://github.com/natario1/CameraView

 

natario1/CameraView

๐Ÿ“ธ A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame proces...

github.com

 

1. CameraView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‚ฌ์ง„์„ ์ดฌ์˜ํ•˜๊ฑฐ๋‚˜ ๋™์˜์ƒ์„ ๋…นํ™”ํ•˜๊ธฐ ์‰ฝ๋„๋ก ๋งŒ๋“ค์–ด์ง„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

๊ณต์‹ ์›น์‚ฌ์ดํŠธ ์ฃผ์†Œ : https://natario1.github.io/CameraView/

 

CameraView

A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs.

natario1.github.io

 


2. CameraView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ง‘์ค‘์ ์œผ๋กœ ๋ณด์•„์•ผ ํ•  ๋ถ€๋ถ„์€ Real-Time Filter ์—ฌ๋ถ€์™€, ํ•„ํ„ฐ๋ฅผ ์ปค์Šคํ…€ ๊ฐ€๋Šฅํ•œ์ง€์˜ ์—ฌ๋ถ€์ด๋‹ค. ๋˜ํ•œ, ํ•„ํ„ฐ์˜ ๊ฐ๋„๋ฅผ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋„ ์‚ดํŽด๋ณด์•„์•ผ ํ•œ๋‹ค.

https://natario1.github.io/CameraView/docs/filters

์œ„์˜ ๋งํฌ๋Š” CameraView ๊ณต์‹ ์‚ฌ์ดํŠธ์˜ Real-Time Filter ๋ฌธ์„œ์ด๋‹ค.

๋ฌธ์„œ์— ์˜ํ•˜๋ฉด, ๋ฆฌ์–ผํƒ€์ž„ ํ•„ํ„ฐ๋Š” ์นด๋ฉ”๋ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ์‹œ์ ์— ์ ์šฉ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

์นด๋ฉ”๋ผ ํ•„ํ„ฐ๋Š” XML attribute ์—์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ๊ณ , ์นด๋ฉ”๋ผ ๊ฐ์ฒด์˜ ์ƒ๋ช…์ฃผ๊ธฐ๋™์•ˆ cameraView.setFilter() ๋ฅผ ์ด์šฉํ•ด ์–ธ์ œ๋“ ์ง€ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

cameraView.setFilter(Filters.BLACK_AND_WHITE.newInstance());
cameraView.setFilter(Filters.VIGNETTE.newInstance());
cameraView.setFilter(Filters.SEPIA.newInstance());

 

CameraView ์—์„œ ์ œ๊ณตํ•˜๋Š” ํ•„ํ„ฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค

๊ธฐ๋ณธ ํ•„ํ„ฐ๋ฅผ NoFilter( Filters.NONE) ์ด๋ผ๊ณ ํ•˜๋ฉฐ ์ด์ „์— ์„ค์ • ํ•œ ๋‹ค๋ฅธ ํ•„ํ„ฐ๋ฅผ ์ง€์šฐ๊ณ  ๋‹ค์‹œ ์ •์ƒ์œผ๋กœ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.

(ํ•„ํ„ฐ ํด๋ž˜์Šค), (ํ•„ํ„ฐ ๊ฐ’), (XML ๋ฆฌ์†Œ์Šค ๊ฐ’) ์ˆœ์„œ์ด๋‹ค

NoFilter Filters.NONE @string/cameraview_filter_none
AutoFixFilter Filters.AUTO_FIX @string/cameraview_filter_autofix
BlackAndWhiteFilter Filters.BLACK_AND_WHITE @string/cameraview_filter_black_and_white
BrightnessFilter Filters.BRIGHTNESS @string/cameraview_filter_brightness
ContrastFilter Filters.CONTRAST @string/cameraview_filter_contrast
CrossProcessFilter Filters.CROSS_PROCESS @string/cameraview_filter_cross_process
DocumentaryFilter Filters.DOCUMENTARY @string/cameraview_filter_documentary
DuotoneFilter Filters.DUOTONE @string/cameraview_filter_duotone
FillLightFilter Filters.FILL_LIGHT @string/cameraview_filter_fill_light
GammaFilter Filters.GAMMA @string/cameraview_filter_gamma
GrainFilter Filters.GRAIN @string/cameraview_filter_grain
GrayscaleFilter Filters.GRAYSCALE @string/cameraview_filter_grayscale
HueFilter Filters.HUE @string/cameraview_filter_hue
InvertColorsFilter Filters.INVERT_COLORS @string/cameraview_filter_invert_colors
LomoishFilter Filters.LOMOISH @string/cameraview_filter_lomoish
PosterizeFilter Filters.POSTERIZE @string/cameraview_filter_posterize
SaturationFilter Filters.SATURATION @string/cameraview_filter_saturation
SepiaFilter Filters.SEPIA @string/cameraview_filter_sepia
SharpnessFilter Filters.SHARPNESS @string/cameraview_filter_sharpness
TemperatureFilter Filters.TEMPERATURE @string/cameraview_filter_temperature
TintFilter Filters.TINT @string/cameraview_filter_tint
VignetteFilter Filters.VIGNETTE @string/cameraview_filter_vignette

 

ํ•„ํ„ฐ ์ปจํŠธ๋กค

(1) camerView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํ•„ํ„ฐ๋ฅผ ์ปค์Šคํ…€ํ•˜์—ฌ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

Advanced users with OpenGL experience can create their own filters by implementing the Filter interface and passing in a fragment shader and a vertex shader that will be used for drawing.

OpenGL ๊ฒฝํ—˜์ด ์žˆ๋Š” ๊ณ ๊ธ‰์‚ฌ์šฉ์ž๋Š” filter ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ , drawing ์— ์‚ฌ์šฉ๋  fragment shader ์™€  vertex shader ๋ฅผ ์ „๋‹ฌํ•ด์„œ ์ž์ฒด ํ•„ํ„ฐ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค

์ฆ‰, ํ•„ํ„ฐ๋ฅผ ์ปค์Šคํ…€ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์–ด๋Š์ •๋„ OpenGL ์— ๋Œ€ํ•œ ์ง€์‹์ด ํ•„์š”ํ•˜๋‹ค๋Š” ์˜๋ฏธ์ธ๊ฒƒ ๊ฐ™๋‹ค.

 

Simple filters

static fragment shader ๊ฐ€ ์žˆ๋Š” ๋‹จ์ˆœํ•œ ํ•„ํ„ฐ์˜ ๊ฒฝ์šฐ์—๋Š” SimpleFilter ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ์ž‘์—…ํ•„ํ„ฐ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

Filter filter = new SimpleFilter(myFragmentShader);

 

More complex filters

We recommend:

  • Subclassing BaseFilter instead of implementing Filter, since that takes care of most of the work
  • If accepting parameters, implementing OneParameterFilter or TwoParameterFilter as well

Most of all, the best way of learning is by looking at the current filters implementations in the com.otaliastudios.cameraview.filters package.

๋ณต์žกํ•œ ํ•„ํ„ฐ ์‚ฌ์šฉ์— ์žˆ์–ด์„œ๋Š” Filter ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค๋Š” BaseFilter ํด๋ž˜์Šค๋ฅผ ์ƒ์†ํ•ด์„œ ์‚ฌ์šฉํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•˜๊ณ , com.otaliastudios.cameraview.filters package ๋ฅผ ๊ณต๋ถ€ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•˜๊ณ  ์žˆ๋‹ค.

 

(2) gesture ๋ฅผ ์ง€์›ํ•œ๋‹ค

https://natario1.github.io/CameraView/docs/gestures

FilterControl ์ด๋ผ๋Š” ์ œ์Šค์ฒ˜ ๋™์ž‘์„ ํ†ตํ•ด ์‹ค์‹œ๊ฐ„ ํ•„ํ„ฐ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค.

FilterControl ์€ FILTER_CONTROL_1 ๊ณผ FILTER_CONTROL_2 ๋‘๊ฐœ๊ฐ€ ์žˆ๋Š”๋ฐ, ์‹ค์‹œ๊ฐ„ ํ•„ํ„ฐ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ ๋‘๊ฐœ๋ฅผ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋Š” ์ปจํŠธ๋กค์ด๋‹ค.

FILTER_CONTROL_1 Controls the first parameter (if any) of a real-time filter. PINCH SCROLL_HORIZONTAL SCROLL_VERTICAL
FILTER_CONTROL_2 Controls the second parameter (if any) of a real-time filter. PINCH SCROLL_HORIZONTAL SCROLL_VERTICAL

์ด ์™ธ์—๋„ ํ™”๋ฉด์„ ํ™•๋Œ€ํ•˜๊ณ , ๊ธธ๊ฒŒ ๋ˆ„๋ฅด๋Š” ๋“ฑ์˜ ์ œ์Šค์ฒ˜๋ฅผ ์ง€์›ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

 

(3) camerView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” DuotoneFilter (์ด์ค‘ ํ†ค ํšจ๊ณผ) ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•„ํ„ฐ ์ปค์Šคํ…€์— ๊ด€๋ จํ•˜์—ฌ ํ•„์š”ํ• ์ˆ˜๋„ ์žˆ๋Š” ์ •๋ณด๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด ๊ธฐ์ˆ ํ•จ.

duotoneFilter.setFirstColor(Color.RED);
duotoneFilter.setSecondColor(Color.GREEN);

๋“€์˜คํ†ค์ด๋ž€ ๋Œ€์กฐ๋˜๋Š” ๋‘ ๊ฐ€์ง€ ์ƒ‰์ƒ์œผ๋กœ ๊ตฌ์„ฑ๋œ ๊ฒƒ์„ ๋งํ•œ๋‹ค. ๊ทธ๋ž˜์„œ ํ•œ๊ตญ๋ง๋กœ๋Š” 2์ƒ‰ ๊ทธ๋ฆผ์ด๋ผ๊ณ ๋„ ํ•จ.

์‚ฌ์ง„์œผ๋กœ ๋ณด๋ฉด ์ดํ•ด๊ฐ€ ๋น ๋ฅด๋‹ค. ์•„๋ž˜๋Š” Blue ์™€ Red ์ƒ‰์ƒ์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋“€์˜คํ†ค ์ด๋ฏธ์ง€์ด๋‹ค.

๊ทธ๋Ÿฌ๋‚˜, ์œ„์˜ ์˜ˆ์‹œ๋Š” ๋””์ž์ด๋„ˆ๊ฐ€ ์ž์ฒด์ ์œผ๋กœ ๋งŒ๋“  ๋“€์˜คํ†ค ์ด๋ฏธ์ง€์ด๊ธฐ ๋•Œ๋ฌธ์—, CameraView ์˜ ๋“€์˜คํ†ค ํ•„ํ„ฐ๋Š” ์–ด๋–ค์‹์œผ๋กœ ๊ฒฐ๊ณผ๊ฐ€ ์ถœ๋ ฅ๋ ์ง€ ํ™•์ธํ•ด ๋ณด์•„์•ผ ํ•œ๋‹ค. ์•„๋ž˜์ฒ˜๋Ÿผ ์ƒ‰์ด ์น™์น™ํ•˜๊ฒŒ ๋‚˜์˜ฌ ์ˆ˜๋„ ์žˆ์Œ.

 

(4) camerView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” Multi Filter ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

ํ•„ํ„ฐ ์ปค์Šคํ…€์— ๊ด€๋ จํ•˜์—ฌ ํ•„์š”ํ• ์ˆ˜๋„ ์žˆ๋Š” ์ •๋ณด๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด ๊ธฐ์ˆ ํ•จ.

CameraView ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ํ•„ํ„ฐ ๋‘๊ฐœ๋ฅผ ๋™์‹œ์— ์ ์šฉํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.

camera.setFilter(new MultiFilter(firstFilter, secondFilter, thirdFilter));

 

Comments