opencv 学习总结


1. Mat  to IplImage* 的方法

#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Chroma.h"
#include "cv.h"
#include "highgui.h"
using namespace concurrency;
using namespace concurrency::fast_math;

using namespace cv;
using namespace std;
void main(int argc, char ** argv)
{
	Mat frame_dest = imread("bule.jpg");
	IplImage *lplImage_dest = &IplImage(frame_dest);
}




2. 取像素点的值,或者设置像素点的值

#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp> 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Chroma.h"
#include "cv.h"
#include "highgui.h"
using namespace concurrency;
using namespace concurrency::fast_math;

using namespace cv;
using namespace std;
void main(int argc, char ** argv)
{
	Mat _src_frame = imread("bule.jpg");
	Mat _background_frame = imread("red.jpg");
	Mat frame_YCbCr;
	IplImage *lplImage_src = &IplImage(_src_frame);
	IplImage *lplImage_background = &IplImage(_background_frame);
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			if(i*j>50)
			{
				CV_IMAGE_ELEM(lplImage_background, unsigned char, i, j * 3 + 0) = _src_frame.at<Vec3b>(i, j).val[0];
				CV_IMAGE_ELEM(lplImage_background, unsigned char, i, j * 3 + 1) = _src_frame.at<Vec3b>(i, j).val[1];
				CV_IMAGE_ELEM(lplImage_background, unsigned char, i, j * 3 + 2) = _src_frame.at<Vec3b>(i, j).val[2];
			}
		}
	}
}


3. 图像裁剪


#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp> 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Chroma.h"
#include "cv.h"
#include "highgui.h"

using namespace concurrency;
using namespace concurrency::fast_math;

using namespace cv;
using namespace std;

void main(int argc, char ** argv)
{

	Mat frame_src = imread("bule.jpg");
	Rect rect(col / 2, row/2, 300, 200);

	Mat partImg = frame_src(rect);

	imwrite("part_image.jpg", partImg);
}



4. 高斯滤波和颜色空间转换

#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp> 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Chroma.h"
#include "cv.h"
#include "highgui.h"
using namespace concurrency;
using namespace concurrency::fast_math;

using namespace cv;
using namespace std;
void main(int argc, char ** argv)
{
	Mat _src_frame = imread("bule.jpg");
	Mat frame_YCbCr;IplImage *lplImage_src = &IplImage(_src_frame);
	int row = _src_frame.rows;
	int col = _src_frame.cols;
	GaussianBlur(_src_frame, frame_GaussianBlur, Size(5, 5), 0, 0);
	cvtColor(frame_GaussianBlur, frame_YCbCr, CV_BGR2YCrCb);
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			Cb_value = frame_YCbCr.at<Vec3b>(i, j).val[1];
			Cr_value = frame_YCbCr.at<Vec3b>(i, j).val[2];
		}
	}
}


</pre><pre>
5. 图片加水印

#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp> 
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>
#include <vector>
#include "Chroma.h"
#include "cv.h"
#include "highgui.h"


using namespace concurrency;
using namespace concurrency::fast_math;

using namespace cv;
using namespace std;

void cvText(IplImage* img, const char* text, int x, int y)
{
	CvFont font;
	double hscale = 1.0;
	double vscale = 1.0;
	int linewidth = 2;
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC, hscale, vscale, 0, linewidth);
	CvScalar textColor = cvScalar(0, 255, 255);
	CvPoint textPos = cvPoint(x, y);
	cvPutText(img, text, textPos, &font, textColor);
}
void main(int argc, char **argv)
{
    Mat frame_background = imread("bule.jpg");
	lplImage_background = &IplImage(frame_background);
	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 2, 8);
	cvPutText(lplImage_background, "www.Hello.com!", cvPoint(120, 50), &font, CV_RGB(0, 255, 0));
	imwrite("water_cover.jpg", frame_background);
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值