๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

๐Ÿ’ก EE's DEV/์˜์ƒ์ฒ˜๋ฆฌ8

[OpenCV] Convert color to grayscale, Image Resizing and Rotation Convert color image to grayscale image1 Algorithm center position ๊ณผ window size(BLK)๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒƒ๋“ค์ด 0๋ณด๋‹ค ์ž‘์„ ๊ฒฝ์šฐ์—๋Š” ๋‹ค์‹œ ์ž…๋ ฅํ•˜๋„๋ก do-while๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค. (out of boundary) ์‹œ์ž‘ํ•˜๋Š” ์ง€์ ์„ startX, startY, ๋๋‚˜๋Š” ์ง€์ ์„ endX, endY ๋กœ ์ •์˜ํ•œ๋‹ค. > startX = (centerX - BLK width) ? width : centerX + BLK;startY = (centerY - BLK height) ? h.. 2018. 9. 3.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 ์ด์ง„ํ™” ํŠธ๋ž™๋ฐ”, ๋ชจํด๋กœ์ง€ - ์นจ์‹ ํŒฝ์ฐฝ ์—ด๋ฆผ ๋‹ซํž˜ ์—ฐ์‚ฐ Binarization, ์ด์ง„ํ™”threshold ๊ฐ’์„ ์ •ํ•œ ํ›„, ํ•œ์ชฝ์€ 0์œผ๋กœ ๋‹ค๋ฅธ ํ•œ์ชฝ์€ 1 ๋˜๋Š” 255๋กœ ๋ฐ”๊พธ๋Š” ์ž‘์—… ์ด์ง„ํ™” ํŠธ๋ž™๋ฐ” ์„ค์ • void binaryzationTrackbar(int, void*){ out2 = out1.clone(); for (int y = 0; y = value) out2.at(y, x) = 255; else out2.at(y, x) = 0; } } imshow("edgeBinarization", out2);} Morphology, ๋ชจํด๋กœ์ง€ ์˜์ƒ ๋‚ด ๊ฐ ๋ฐ์€ ์˜์—ญ์ด๋‚˜ ์–ด๋‘์šด ์˜์—ญ์„ ์ถ•์†Œ, ํ™•๋Œ€ํ•˜๋Š” ๊ธฐ๋ฒ•์ด์ง„ํ™”.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 ํžˆ์Šคํ† ๊ทธ๋žจ, ์ •๊ทœํ™”, ์ŠคํŠธ๋ ˆ์นญ, ๊ท ๋“ฑํ™” Histogram, ํžˆ์Šคํ† ๊ทธ๋žจ์˜์ƒ ๋‚ด ๊ฐ ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๊ฐ’์— ํ•ด๋‹นํ•˜๋Š” ํ”ฝ์…€์˜ ๊ฐœ์ˆ˜๋ฅผ ํ•จ์ˆ˜์˜ ๊ผด๋กœ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์„ ํžˆ์Šคํ† ๊ทธ๋žจ์ด๋ผ๊ณ  ํ•œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆ˜์‹์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. h(g)=ngโ€‹g = ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๊ณ  ๋ฒ”์œ„๋Š” 0~255n_g = ๊ทธ๋ ˆ์ด์Šค์ผ€์ผ ๊ฐ’์ด g ์ธ ํ”ฝ์…€์˜ ๊ฐœ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค h(g) ํ•จ์ˆ˜์˜ ๊ฐ’์€ ์˜์ƒ์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ์ž‘๊ฑฐ๋‚˜ ์ปค์งˆ ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ n_g ๋ฅผ ์˜์ƒ์˜ ์ „์ฒด ํ”ฝ์…€์˜ ๊ฐœ์ˆ˜๋กœ ๋‚˜๋ˆ„๋Š” ์ •๊ทœํ™”(normalize) ๊ณผ์ •์„ ํ†ตํ•˜์—ฌ ํžˆ์Šคํ† ๊ทธ๋žจ์„ ํ‘œํ˜„ํ•˜๊ธฐ๋„ ํ•œ๋‹ค. ์ •๊ทœํ™”๋œ ํžˆ์Šคํ† ๊ทธ๋žจ ์ •๊ทœํ™”๋œ ํžˆ์Šคํ† ๊ทธ๋žจ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆ˜์‹์œผ๋กœ ํ‘œํ˜„๋˜๋ฉฐ, ํŠน์ • ๊ทธ๋ ˆ์ด ์Šค์ผ€์ผ(gray scale) ๊ฐ’์ด ๋‚˜ํƒ€๋‚˜๋Š” ํ™•๋ฅ ์˜ ๊ฐœ๋…์œผ๋กœ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋‹ค. p(g) = ํ™•๋ฅ  ๊ฐ’, ํ™•๋ฅ ์„ ์˜๋ฏธํ•˜๋Š” p๋กœ ๋ณ€๊ฒฝ (probabili.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ด์šฉํ•˜๊ธฐ - Canny Edge detector, Finding contours OpenCV ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์˜ˆ์ œ Sobel Derivatives https://docs.opencv.org/master/d2/d2c/tutorial_sobel_derivatives.htmlLaplace Operator https://docs.opencv.org/master/d5/db5/tutorial_laplace_operator.htmlCanny Edge Detector https://docs.opencv.org/master/da/d5c/tutorial_canny_detector.htmlHough Circle Transform https://docs.opencv.org/master/d4/d70/tutorial_hough_circle.htmlFinding contours in your image https:.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 Edge ๊ฒ€์ถœ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์—์ง€ ๊ฒ€์ถœ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์•Œ์•„๋ณด๊ธฐ 1. ์†Œ๋ฒจ, ํ”„๋ฆฌ์œ—, ๋กœ๋ฒ„์ธ , ๋ผํ”Œ๋ผ์‹œ์•ˆ ์žฅ๋‹จ์  2. ๊ฐ€์šฐ์‹œ์•ˆ -> ๋ผํ”Œ๋ผ์‹œ์•ˆ vs ๋ผํ”Œ๋ผ์‹œ์•ˆ ๋น„๊ต Edge Edge๋Š” ๊ฒฝ๊ณ„์„ , ์œค๊ณฝ์„ ์„ ์˜๋ฏธํ•จ์˜์ƒ์—์„œ edge๋Š” ์˜์ƒ์˜ ๋ฐ๊ธฐ๊ฐ€ ๋‚ฎ์€ ๊ฐ’์—์„œ ๋†’์€ ๊ฐ’์œผ๋กœ / ๋†’์€ ๊ฐ’์—์„œ ๋‚ฎ์€ ๊ฐ’์œผ๋กœ ๋ณ€ํ•˜๋Š” ๋ถ€๋ถ„์„ ๋œปํ•จedge๋Š” ์˜์ƒ์•ˆ์— ์žˆ๋Š” ๊ฐ์ฒด์˜ ๊ฒฝ๊ณ„๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ๊ฒƒ์œผ๋กœ, ๋ชจ์–‘๊ณผ ๋ฐฉํ–ฅ์„ฑ์„ ํƒ์ง€ํ•  ์ˆ˜ ์žˆ์Œ์—์ง€์— ํ•ด๋‹นํ•˜๋Š” ํ™”์†Œ๋ฅผ ์ฐพ๋Š” ๊ณผ์ •์„ edge detection ์ด๋ผ ํ•จ 1์ฐจ ๋ฏธ๋ถ„ edge๋Š” ๋ช…์•”(๋ฐ๊ธฐ)์˜ ๋ณ€ํ™”๊ฐ€ ํฐ ์ง€์ ๋ช…์•”์˜ ๋ณ€ํ™”์œจ์ธ ๊ธฐ์šธ๊ธฐ(gradient)๋ฅผ ๊ฒ€์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•, 1์ฐจ ๋ฏธ๋ถ„์ด๋ผ ํ•จ์ˆ˜ํ‰ ๋ฐฉํ–ฅ ๋ฏธ๋ถ„ G(x) = f(x-1, y) - f(x+1, y)์ˆ˜์ง ๋ฐฉํ–ฅ ๋ฏธ๋ถ„ G(y) = f(x, y-1) - f(x, y+1)Edge = |G(.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] OpenCV2 ํ”ฝ์…€ ์—ฐ์‚ฐ – ํ‰๊ท , ๋ง์…ˆ, ๋บ„์ƒ˜, ํ‰๊ท  ๊ฐ’, ๊ฐ€์ค‘ ํ‰๊ท  ๊ฐ’, ๊ฐ€์šฐ์‹œ์•ˆ ํ•„ํ„ฐ ๋‘ ์ด๋ฏธ์ง€๊ฐ„ ํ”ฝ์…€์˜ ํ‰๊ท  ๊ฐ’ ๊ตฌํ•˜๊ธฐvoid avgImage(Mat &img1, Mat &img2, Mat &out){ for (int y = 0; y ๋‘ ์ด๋ฏธ์ง€๊ฐ„ ํ”ฝ์…€์˜ ๋”ํ•œ ๊ฐ’ ๊ตฌํ•˜๊ธฐ#include #include #include using namespace cv; void addImage(Mat &img1, Mat &img2, Mat &out){ for (int y = 0; y < out.siz.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 ์ด๋ฏธ์ง€ ๊ธฐ๋ณธ ์—ฐ์‚ฐ, ์ƒ‰์ƒ ๋ชจ๋ธ ์žก์Œ ์ƒ์„ฑ#include #include #include using namespace std;using namespace cv; void salt(Mat &image, int snum){ for (int n = 0; n < snum; n++) { int x = rand() % image.cols; int y = rand() % image.rows; if (image.channels() == 1) // Gray { image.at(y, x) = 0; // ํฐ์ƒ‰ ์žก์Œ } else if (image.channels() == 3) // RGB { image.at(y, x)[0] = 255; image.at(y, x)[1] = 255; image.at(y, x)[2] = 255; } }} int main(){ M.. 2017. 2. 27.
[์˜์ƒ์ฒ˜๋ฆฌ] openCV2 ์‹œ์ž‘ํ•˜๊ธฐ - ํ”ฝ์…€์ด๋ž€?, Mat ์ด๋ฏธ์ง€ ๊ฐ์ฒด Pixel, ํ”ฝ์…€ ํ•˜๋‚˜ ๋‹น 0~255 ์ˆซ์ž๋กœ ๋ช…๋„๋ฅผ ๋‚˜ํƒ€๋ƒ„ํ•ด์ƒ๋„ 1920x1080 ๋ผ๋Š” ๊ฑด ๊ฐ€๋กœ 1920 ํ”ฝ์…€ x ์„ธ๋กœ 1080 ํ”ฝ์…€์„ ๋œปํ•จ 0~255๋กœ๋งŒ ์ด๋ฏธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉด Grayscale(ํ‘๋ฐฑ) ๋ฐ–์— ์•ˆ๋จ -> ํ•œ ํ”ฝ์…€๋‹น 1 byte์ƒ‰์ƒ์„ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ๊ฐ๊ฐ R, G, B ๋งˆ๋‹ค 0~255 ๊ฐ’์„ ๊ฐ€์ง -> ํ•œ ํ”ฝ์…€๋‹น 3 byte(R + G + B) / 3 = ํ‘๋ฐฑ ๋ช…๋„ ๊ฐ’ ์ด๋ฏธ์ง€ ํŒŒ์ผ ํฌ๋งท.raw ํŒŒ์ผ - ์šฉ๋Ÿ‰์ด ํฌ์ง€๋งŒ ํ”ฝ์…€ ๊ฐ’์ด ํ•˜๋‚˜๋„ ๊นจ์ง€์ง€ ์•Š์œผ๋ฏ€๋กœ C/C++ ์—์„œ ํŒŒ์ผ์„ ๋ฐ”๋กœ ์ฝ์–ด์„œ ์ƒ‰์ƒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Œ.bmp ํŒŒ์ผ - rawํŒŒ์ผ ๋ณด๋‹ค ์šฉ๋Ÿ‰์ด ์ž‘์•„ ๋” ๋น ๋ฅธ ์ „์†ก ๊ฐ€๋Šฅ. Windows์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋ฉฐ C++ ๊ธฐ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์Œ.jpg .gif .png ํŒŒ์ผ - ์šฉ๋Ÿ‰์ด ์ž‘์ง€๋งŒ ํŒŒ์ผ์„ ๋ฐ”๋กœ ์ฝ์„ .. 2017. 2. 18.
728x90