gray

【OpenCV】学习笔记(一):基础操作部分

感情迁移 提交于 2020-03-01 11:04:19
前言:跟着 浅墨 大神,学习OpenCV3后,笔记如下。 1 基础知识 1.1 加载、修改、保存图像 加载 cv::imread 保存 cv::cvtColor 保存 cv::imwrite Mat image = imread("E:/result/MyPic1.png", 0); //路径,0代表灰度打开 imshow("image1", image); Mat gray_image; cvtColor(image, gray_image, COLOR_BGR2GRAY); //转换色彩空间 imshow("out_gray_image", gray_image); imwrite("E:/result/Mypic1_opencv.jpg", gray_image); //保存图片 1.2 获取图像像素指针 void showCamera() { VideoCapture capture(0); //从摄像头中读取视频 while (true) { Mat frame; capture >> frame; namedWindow("读取视频"); imshow("读取视频", frame); waitKey(30); } } void showCapture() { VideoCapture capture; capture.open("E:/result/MyVid.avi"

opencv学习笔记17-Canny算法

时光怂恿深爱的人放手 提交于 2020-02-29 14:23:18
只用来记录学习笔记 Canny算法 int t1_value = 50 ; const char * OUTPUT_TITLE = "Canny Result" ; cvtColor ( src , gray_src , CV_BGR2GRAY ) ; //转灰度图像 blur ( gray_src , gray_src , Size ( 3 , 3 ) , Point ( - 1 , - 1 ) , BORDER_DEFAULT ) ; //模糊 Canny ( gray_src , edge_output , t1_value , t1_value * 2 , 3 , false ) ; //gray_src:灰度图像 //edge_output //t1_value:低阈值 //t1_value * 2:高阈值 //3:孔径大小 imshow ( OUTPUT_TITLE , edge_output ) ; 效果图: 来源: CSDN 作者: 没有改不了的bug 链接: https://blog.csdn.net/weixin_44177447/article/details/104572510

opencv之傅里叶变换

南楼画角 提交于 2020-02-12 22:55:20
图像处理一般分为空间域处理和频率域处理 空间域处理是直接对图像内的像素进行处理。主要划分为灰度变换核空间滤波两种形式, 灰度变换对图像内的单个像素进行处理,滤波处理涉及对图像质量的改变 频率域处理是先将图像变换到频率域,然后在频率域对图像进行处理,最后通过反变换将图像变为空间域。 傅里叶变换可以将图像变换为频率域, 傅立叶反变换将频率域变换为空间域 时域是以时间为坐标轴表示动态信号的关系, 频域则是把信号变为一频率为坐标轴表示出来。 时域是实际存在的,而频域则是数学构造。 numpy实现傅里叶变换 函数 dst = numpy.fft.fft2(src) dst为一个复数数组 src 原始图像的类型应是灰度图像 该函数处理之后就能得到图像的频谱信息 零频率分量位于频谱图像的左上角 函数 dst = numpy.ffr.fftshift(src) 使用该函数处理后,图像频谱中的零频率分量会被移到频域图像的中心位置 对图像傅里叶变换后得到的是一个复数数组,为了显示图像需要将他们的值调整到 [0 , 255 ] 的灰度空间 公式为 像素新值 = 20 * np.log( np.abs( 频谱值 ) ) 1 import cv2 2 import numpy as np 3 import matplotlib.pyplot as plt 4 img = cv2.imread("/home

OpenCV--图像特征(harris角点检测)

陌路散爱 提交于 2020-02-12 18:18:38
图像特征--harris角点检测 基本原理 cv2.cornerHarris() - img: 数据类型为 float32 的入图像 - blockSize: 角点检测中指定区域的大小 - ksize: Sobel求导中使用的窗口大小 - k: 取值参数为 [0,04,0.06] import cv2 import numpy as np img = cv2.imread('test_1.jpg') print ('img.shape:',img.shape) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # gray = np.float32(gray) dst = cv2.cornerHarris(gray, 2, 3, 0.04) print ('dst.shape:',dst.shape) 效果: img.shape: (800, 1200, 3) dst.shape: (800, 1200) img[dst>0.01*dst.max()]=[0,0,255] cv2.imshow('dst',img) cv2.waitKey(0) cv2.destroyAllWindows() 效果: 来源: https://www.cnblogs.com/SCCQ/p/12299472.html

bootstrap实现首页轮播加缩放

拈花ヽ惹草 提交于 2020-02-11 18:37:35
需要用到一些组件 BootStrap组件 给个官网网址(自己想要的再找):https://v2.bootcss.com/index.html 需要一些其他的相关文件,这里都有: 链接: https://pan.baidu.com/s/16O9eZm3KphXCS7tFW8asFg 提取码: 7md4 复制这段内容后打开百度网盘手机App,操作更方便哦 1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 4 <head> 5 <meta charset="utf-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1"> 8 <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> 9 <title>商城首页</title> 10 11 <!-- Bootstrap --> 12 <link href="../css/bootstrap.css" rel="stylesheet"> 13 14 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

传入一张图,生成它的油画版!(python实现)(转 )

别等时光非礼了梦想. 提交于 2020-02-08 19:40:23
来自:https://blog.csdn.net/miracleoa/article/details/104210597import cv2 import numpy def oilPainting(img, templateSize, bucketSize, step): # templateSize模板大小,bucketSize桶阵列,step模板滑动步长 gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) gray = ((gray / 256) * bucketSize).astype(int) # 灰度图在桶中的所属分区 h, w = img.shape[:2] oilImg = numpy.zeros(img.shape, numpy.uint8) # 用来存放过滤图像 for i in range(0, h, step): top = i - templateSize bottom = i + templateSize + 1 if top < 0: top = 0 if bottom >= h: bottom = h - 1 for j in range(0, w, step): left = j - templateSize right = j + templateSize + 1 if left < 0: left = 0

传入一张图,生成它的油画版!(python实现)

徘徊边缘 提交于 2020-02-08 05:33:34
文章目录 一、函数 1、主函数 2、使用方法 二、效果展示 1、原图像 2、油画版效果 一、函数 1、主函数 import cv2 import numpy def oilPainting ( img , templateSize , bucketSize , step ) : # templateSize模板大小,bucketSize桶阵列,step模板滑动步长 gray = cv2 . cvtColor ( img , cv2 . COLOR_RGB2GRAY ) gray = ( ( gray / 256 ) * bucketSize ) . astype ( int ) # 灰度图在桶中的所属分区 h , w = img . shape [ : 2 ] oilImg = numpy . zeros ( img . shape , numpy . uint8 ) # 用来存放过滤图像 for i in range ( 0 , h , step ) : top = i - templateSize bottom = i + templateSize + 1 if top < 0 : top = 0 if bottom >= h : bottom = h - 1 for j in range ( 0 , w , step ) : left = j - templateSize

【学习笔记】OpenCV+C++(二)

蹲街弑〆低调 提交于 2020-02-07 23:30:53
Mat对象 Mat对象与IplImage对象 Mat对象OpenCV2.0之后引进的图像数据结构、自动分配内存、不存在内存泄漏的问题,是面向对象的数据结构,分了两部分,头部和数据部分。 IplImage是从2001年OpenCV发布之后就一直存在,是C语言风格的数据结构,需要开发者自己分配与管理内存,对大的程序使用它容易导致内存泄漏问题。 //Mat对象构造函数与常用方法 // Mat() // Mat(int rows,int cols,int type) // Mat(Size size,int type) // Mat(int rows,int cols,int type,const Scalar &s) // Mat(Size size,int type,const Scalar &s) // Mat(int ndims,const int *sizes,int type) // Mat(int ndims,const int *sizes,int type,const Scalar &s) // // 常用方法: // void copyTo(Mat mat) // void convertTo(Mat dst,int type) // Mat clone() // int channels() // int depth() // bool empty() //

Canny边缘检测

↘锁芯ラ 提交于 2020-02-07 14:38:59
步骤 :噪声去除,计算图像梯度,非极大值抑制, 滞后阈值 cv2.Canny()可以完成以上几步。 import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread('messi5.jpg',0) edges = cv2.Canny(img,100,200) plt.subplot(121),plt.imshow(img,cmap = 'gray') plt.title('Original Image'), plt.xticks([]), plt.yticks([]) plt.subplot(122),plt.imshow(edges,cmap = 'gray') plt.title('Edge Image'), plt.xticks([]), plt.yticks([]) plt.show() 来源: https://www.cnblogs.com/h694879357/p/12272609.html

纯JS写的小众游戏——走四棋

这一生的挚爱 提交于 2020-02-03 09:00:48
过年正赶上新冠病毒不让出门,在家闲着没事,偶尔玩了一下老家流行的游戏(走四棋),然后就想把这个游戏用JS写出来,先练了一下贪吃蛇,等下也会在我的博客中单独贴出来,按照贪吃蛇动态生成dom元素的方法,粗略的写了一下走四棋,有很多地方存在代码冗余,设计也有待优化,但是基本效果是有了,首次效果做成这样,我也很满意了,话不多说,上代码,仅供大家参考。 <html> <body> 步数:<input type="text" value="0" id="stepCount" disabled></input> <button id="rule" οnclick="rule()">玩法说明</button> <script> var stepCount = 0; var user; //创建棋盘 function Map(){ //属性 this.width = 30; this.height = 30; this.jianju = 100;//每个棋子之间的间距 this.backgroundColor = "gray"; //棋盘的每一个可走点,定义为二维数组 this.route = [[1,1,"gray",null],[2,1,"gray",null],[3,1,"gray",null],[4,1,"gray",null],[1,2,"gray",null],[2,2,"gray"