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