Opencv改进型图片素描风(实时摄像头+Sobel边缘检测+三通道图片Mat上叠加另外一个单通道图片Mat)
2016-09-30 16:40
411 查看
惯例效果图震楼
感觉物体比人看上去好看多了。。。摔!!
惯例opencv配置环境地址:http://blog.csdn.net/zmdsjtu/article/details/52235056
实现代码如下:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
using namespace cv;
void sumiao(Mat &image);
int main() {
VideoCapture cap(0);
Mat frame;
while (waitKey(30) != 27)
{
cap >> frame;
sumiao(frame);
}
}
void sumiao(Mat &image) {
Mat image2 = image.clone();
cvtColor(image, image, CV_BGR2GRAY);//灰度图
Mat sobel_x, sobel_y;
Sobel(image, sobel_x, CV_16S, 1, 0); // Sobel
Sobel(image, sobel_y, CV_16S, 0, 1);
Mat sobel;
sobel = abs(sobel_x) + abs(sobel_y);
double sobmin, sobmax;
minMaxLoc(sobel, &sobmin, &sobmax);
Mat sobelImage;
sobel.convertTo(sobelImage, CV_8U, -255.0 / sobmax, 255);
int 倍数 = 2;
cv::resize(sobelImage, sobelImage, Size(640/倍数, 480/倍数));
for (int i = 0; i < sobelImage.rows; ++i) {
for (int j = 0; j < sobelImage.cols; ++j) {
image2.data[3*(j + i*image2.cols+image2.cols-sobelImage.cols)] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+1] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+2] = sobelImage.data[j + i*sobelImage.cols];
}
}
imshow("素描图", image2);
}
最后显示图片的时候在三通道的彩色图上叠加了单通道的灰度图,代码如下:
image2.data[3*(j + i*image2.cols+image2.cols-sobelImage.cols)] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+1] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+2] = sobelImage.data[j + i*sobelImage.cols];
三通道对应像素点直接都赋值为单通道的值就好
最后祝大家opencv使用愉快~
感觉物体比人看上去好看多了。。。摔!!
惯例opencv配置环境地址:http://blog.csdn.net/zmdsjtu/article/details/52235056
实现代码如下:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
using namespace cv;
void sumiao(Mat &image);
int main() {
VideoCapture cap(0);
Mat frame;
while (waitKey(30) != 27)
{
cap >> frame;
sumiao(frame);
}
}
void sumiao(Mat &image) {
Mat image2 = image.clone();
cvtColor(image, image, CV_BGR2GRAY);//灰度图
Mat sobel_x, sobel_y;
Sobel(image, sobel_x, CV_16S, 1, 0); // Sobel
Sobel(image, sobel_y, CV_16S, 0, 1);
Mat sobel;
sobel = abs(sobel_x) + abs(sobel_y);
double sobmin, sobmax;
minMaxLoc(sobel, &sobmin, &sobmax);
Mat sobelImage;
sobel.convertTo(sobelImage, CV_8U, -255.0 / sobmax, 255);
int 倍数 = 2;
cv::resize(sobelImage, sobelImage, Size(640/倍数, 480/倍数));
for (int i = 0; i < sobelImage.rows; ++i) {
for (int j = 0; j < sobelImage.cols; ++j) {
image2.data[3*(j + i*image2.cols+image2.cols-sobelImage.cols)] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+1] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+2] = sobelImage.data[j + i*sobelImage.cols];
}
}
imshow("素描图", image2);
}
最后显示图片的时候在三通道的彩色图上叠加了单通道的灰度图,代码如下:
image2.data[3*(j + i*image2.cols+image2.cols-sobelImage.cols)] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+1] = sobelImage.data[j + i*sobelImage.cols];
image2.data[3 * (j + i*image2.cols + image2.cols - sobelImage.cols)+2] = sobelImage.data[j + i*sobelImage.cols];
三通道对应像素点直接都赋值为单通道的值就好
最后祝大家opencv使用愉快~
相关文章推荐
- 数字集成电路设计-8-一个简单sobel图像边缘检测加速器的设计,实现,仿真与综合
- OpenCV Canny边缘检测输出写入一个单通道(灰度级)图像
- 数字集成电路设计-8-一个简单sobel图像边缘检测加速器的设计,实现,仿真与综合
- 【OpenCV】边缘检测、梯度计算 Sobel Mat
- OpenCV实现读取摄像头做实时边缘检测
- Opencv实现图片素描风(调用摄像头+中值滤波+拉普拉斯边缘检测)
- 检测浏览器版本低于或者等于IE6时自动跳转到另外一个网页
- matlab边缘检测代码(包含roberts,sobel,prewitt三种算子)
- canny/Sobel/Laplace边缘检测
- Sobel边缘检测算法
- 使用roberts Prewitt Sobel 三种算子对raw格式图像进行边缘检测
- 检测图片里面的直线对(绿线在上蓝线在下的是一个有效线对)
- Robert边缘检测算子的程序。换做其他算子,只要该其中的一个矩阵就行了
- 摄像头 Roberts 算子 边缘检测 opencv
- listview练习,当连接类型为文本时图片地址的文本框隐藏,textbox渲染到客户端的ID不是服务端所写的clientID,只能另外添加一个属性myid
- 图像处理中各种边缘检测的微分算子简单比较(Sobel,Robert, Prewitt,Laplacian,Canny)
- 检测一个图片是否是真实图片
- 发一个网络摄像机实时演示图片!
- 收藏的图片滚动的另外一个代码!
- 图像边缘检测Sobel,Laplace,Canny