카테고리 없음

픽셀 접근 방법.

junl 2021. 7. 16. 14:07

1) at 사용

OpenCV 픽셀 값 접근하기 - cvMat 데이터 구조 (tistory.com)

 

OpenCV 픽셀 값 접근하기 - cvMat 데이터 구조

OpenCV 픽셀 값 접근하기 - cvMat 데이터 구조 저번 OpenCV 픽셀 값 접근하기 - IplImage 데이터구조 포스팅 http://eehoeskrap.tistory.com/33 지난 포스팅에서는 IplImage 데이터 구조에서 픽셀 값에 어떻게 접..

eehoeskrap.tistory.com

//픽셀 접근
#include<opencv2/core.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/highgui.hpp>
#include<iostream>

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)
		{
			image.at<uchar>(y, x) = 125;
		}
		else if (image.channels() == 3)
		{
			image.at<Vec3b>(y, x)[0] = 0; //b
			image.at<Vec3b>(y, x)[1] = 0; //g
			image.at<Vec3b>(y, x)[2] = 255; //r
		}
	}


}

int main(void)
{
	Mat dst = imread("O:/1313.bmp");

	Mat dst2;
	dst.copyTo(dst2);
	cvtColor(dst, dst2, CV_BGR2GRAY,0);
	salt(dst, 120000);
	salt(dst2, 120000);
	imshow("dst소금", dst);
	imshow("dst2소금", dst2);
	
	waitKey(0);
}

 

 

 

참조

OpenCV 기초 - 3. 픽셀 접근 방법 (tistory.com)

 

OpenCV 기초 - 3. 픽셀 접근 방법

이번 글에서는 영상의 픽셀에 접근하여 데이터를 처리하는 방법에 대해서 알아보겠습니다. - at( int x, int y ) 각 원소에 접근하기 위한 방법으로 Mat의 at 메소드를 이용할 수 있습니다. at은 컴파

visionprogrammer.tistory.com