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);
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,OpenCV是一个开源计算机视觉和机器学习软件库,用于开发图像和视频处理应用程序。通过使用OpenCV,您可以读取摄像头并显示实时图像,打开视频文件或摄像头文件,并获取视频的相关信息,例如帧宽度、帧高度、帧率和总帧数。 对于学习OpenCV,你可以按照以下步骤进行: 1. 安装OpenCV库:在开始学习OpenCV之前,您需要从OpenCV官方网站下载和安装OpenCV库。根据您的操作系统和编程语言选择合适的版本。 2. 学习基本概念:熟悉OpenCV的基本概念和术语,例如图像和视频的加载、显示、保存以及常用的图像处理操作,如滤波、边缘检测和特征提取等。 3. 掌握OpenCV函数和类:深入了解OpenCV提供的函数和类,例如cv::Mat用于图像和矩阵操作,cv::VideoCapture用于读取和处理视频,以及cv::imshow和cv::waitKey等用于显示图像的函数。 4. 实践项目:通过完成一些实践项目来应用您所学到的知识。例如,利用OpenCV实现人脸检测、目标追踪、图像识别等。 5. 学习资料和资源:查找和阅读OpenCV的官方文档、教程和示例代码,参与开源社区讨论和交流,加入相关的论坛和邮件列表等。 总结起来,学习OpenCV包括安装OpenCV库、学习基本概念、掌握OpenCV函数和类、实践项目以及查找和阅读相关资料和资源。通过不断实践和学习,您将能够更好地理解和应用OpenCV库来开发图像和视频处理应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值