gray

Gray Code

匿名 (未验证) 提交于 2019-12-02 23:26:52
The gray code is a binary numeral system where two successive values differ in only one bit. n Example 1: Input: Output: [0,1,3,2] Explanation: n , a gray code sequence may not be uniquely defined. For example, [0,2,3,1] is also a valid gray code sequence. 00 - 0 10 - 2 11 - 3 01 - 1 Example 2: Input: Output: 解法:格雷码,详情见维基百科: https://zh.wikipedia.org/zh/%E6%A0%BC%E9%9B%B7%E7%A0%81 class Solution { public List<Integer> grayCode(int n) { List<Integer> res = new ArrayList<>(); int tmp = 0; for(int i=0;i<Math.pow(2,n);i++){ tmp = (i>>1)^i; res.add(tmp); } return res; } } 文章来源: https://blog.csdn.net

Python图像灰度变换及图像数组操作

匿名 (未验证) 提交于 2019-12-02 22:54:36
转载自: https://www.jb51.net/article/78762.htm 点击打开链接 使用python以及numpy通过直接操作图像数组完成一系列基本的图像处理 总的想法是:利用PIL库中的Image()函数将图像转为array,通过对array的操作来完成对图像的操作。 numpy简介: NumPy是一个非常有名的 Python 科学计算工具包,其中包含了大量有用的工具,比如数组对象(用来表示向量、矩阵、图像等)以及线性代数函数。 数组对象可以实现数组中重要的操作,比如矩阵乘积、转置、解方程系统、向量乘积和归一化。这为图像变形、对变化进行建模、图像分类、图像聚类等提供了基础。 在上一篇python基本图像操作中,当载入图像时,通过调用 array() 方法将图像转换成NumPy的数组对象。NumPy 中的数组对象是多维的,可以用来表示向量、矩阵和图像。通过对图像的数组进行直接操作,就可以完成很多图像处理。 numpy的相关知识网上有很多资料,作为python科学计算的基础,还是非常值得认真学习的。 使用图像数组进行基本图像操作: 认识图像数组: 通过下面这几个程序我们看一下图像与灰度图的图像数组,以及numpy数组的切片。 ? 1 2 3 4 5 6 7 8 9 10 11 12 # -*- coding: utf-8 -*- from PIL import

Python基本图像处理

匿名 (未验证) 提交于 2019-12-02 22:51:30
相关包 matplotlib PIL cv2 numpy 各种操作 读取图片 1 matplotlib.pylab import numpy as np from matplotlib import pyplot as plt img = plt.imread( 'examples.png' ) print(type(img), img.dtype, np.min(img), np.max(img)) [out] (<type 'numpy.ndarray' >, dtype( 'float32' ), 0.0 , 1.0 ) # matplotlib读取进来的图片是float,0-1 2 PIL.image.open from PIL import Image import numpy as np img = Image.open( 'examples.png' ) print(type(img), np.min(img), np.max(img)) img = np.array(img) # 将PIL格式图片转为numpy格式 print(type(img), img.dtype, np.min(img), np.max(img)) [out] (< class ' PIL . PngImagePlugin . PngImageFile '>, 0, 255) # 注意,

直接可以用的Python和OpenCV检测及分割图像的目标区域例子

匿名 (未验证) 提交于 2019-12-02 22:51:30
第一天 老师:图像处理。 ~.我:他傻啊,切割出来啊,只需要训练感兴趣的部分就好啦。 ~.我:好的(hello?一个U盘?) 第二天 有这么一个文件 看了里面。。。我要爆炸了。。。 > 598M * 15 = 8970M = 8.97G 我的个妈呀。 为了视觉体验,自动屏蔽,请大家自行去谷歌:虫子、worm、bug、insects。。。 三天后 老师: 好的,我看看。 考虑到 视觉忍受能力 ,我用一个可爱的虫子做为一个示例,其他的都差不多,大家自行尝试。 目标是把虫子区域抠出来 环境: 1.2 下载安装opencv3.2 具体思路如下: 1.获取图片,这个简单哈 img_path = r'C:\Users\aixin\Desktop\chongzi.png' img = cv2.imread(img_path) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 1 2 3 看,这不就是你处理初始的样子? 2.转换灰度并去噪声 gray = cv2 .cvtColor (img, cv2 .COLOR _BGR2GRAY) blurred = cv2 .GaussianBlur (gray, ( 9 , 9 ), 0 ) 1 2 我们可以得到这两张图,第一张是灰度图,第二张是去噪之后的,另外说一下,去噪咱们有很多种方法,均值滤波器、高斯滤波器

OpenCV-Python(1)在Python中使用OpenCV进行人脸检测

匿名 (未验证) 提交于 2019-12-02 22:51:30
detector = cv2 . CascadeClassifier ( 'haarcascade_frontalface_default.xml' ) cap = cv2 . VideoCapture ( 0 ) ret , img = cap . read () cv2 . imshow ( 'windowname' , img ) cv2 . waitKey ( 0 ) # 释放摄像头资源 cap . release () gray = cv2 . cvtColor ( img , cv2 . COLOR_BGR2GRAY ) faces = detector . detectMultiScale ( gray , 1.3 , 5 ) for ( x , y , w , h ) in faces : cv2 . rectangle ( img , ( x , y ), ( x + w , y + h ), ( 255 , 0 , 0 ), 2 ) detector = cv2 . CascadeClassifier ( 'haarcascade_frontalface_default.xml' ) cap = cv2 . VideoCapture ( 0 ) while True : ret , img = cap . read () gray = cv2 .

01_opencv_python_基本图像处理

匿名 (未验证) 提交于 2019-12-02 22:51:30
Anaconda: https://www.anaconda.com/download/ Python_whl: https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv cv2.IMREAD_COLOR:彩色图像 cv2.IMREAD_GRAYSCALE:灰度图像 import cv2 # opencv读取的格式是BGR import matplotlib . pyplot as plt import numpy as np % matplotlib inline # img读入的本质上就是数组 img = cv2 . imread ( 'cat.jpg' ) #图像的显示,也可以创建多个窗口 cv2 . imshow ( 'image' , img ) # 等待时间,毫秒级,0表示任意键终止 cv2 . waitKey ( 0 ) cv2 . destroyAllWindows () 我们来将上述图像显示的代码封装成一个函数 def cv_show ( name , img ): cv2 . imshow ( name , img ) cv2 . waitKey ( 0 ) cv2 . destroyAllWindows () 我们可以看看图像的各种基本信息 print ( img . shape ) # 图片形状(h, w, c)

Emgucv使用中常用函数总结

匿名 (未验证) 提交于 2019-12-02 22:06:11
Emgucv常用函数总结: 读取图片 Mat SCr = new Mat(Form1.Path, Emgu.CV.CvEnum.LoadImageType.AnyColor); //根据路径创建指定的灰度图片 Mat scr = new Mat(Form1.Path, Emgu.CV.CvEnum.LoadImageType.Grayscale); 获取灰度 //图像类型转换, bgr 转成 gray 类型。MAT Bw = New MAT CvInvoke.CvtColor(SCr, bw, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray); //相当于二值化图 --黑白 根据大小10判断为0还是255 CvInvoke.Threshold(bw,bw,10,255,Emgu.CV.CvEnum.ThresholdType.BinaryInv); //获取指定区域图片 SCr为mat类型 Rectangle rectangle = new Rectangle(10,10,10,10); SCr = SCr.ToImage<Bgr, byte>().GetSubRect(rectangle).Mat; //将Mat类型转换为Image类型 Image<Bgr, byte> Su = SCr.ToImage<Bgr, byte>(); Image

2000 * 1000的图像截取大小为20 * 20

倾然丶 夕夏残阳落幕 提交于 2019-12-01 22:10:29
digits.png为2000 * 1000,其中每个数字的大小为20 * 20,总共有5000((2000*1000) / (20*20))个数字,类型为[0~9],[0~9]10个数字每个数字有5000/10 = 500个样本对其分割成单个20 * 20的图像并序列化成 #include<iostream> #include <opencv2\opencv.hpp> using namespace cv; using namespace std; int main() { Mat img = imread("1.png"); Mat gray; cvtColor(img, gray, CV_BGR2GRAY); threshold(gray, gray, 0, 255, CV_THRESH_BINARY); // digits.png为2000 * 1000,其中每个数字的大小为20 * 20, // 总共有5000((2000*1000) / (20*20))个数字,类型为[0~9], // [0~9]10个数字每个数字有5000/10 = 500个样本 // 对其分割成单个20 * 20的图像并序列化成(转化成一个一维的数组) int side = 20; int m = gray.rows / side; int n = gray.cols / side; Mat

OpenCV KNN数字分类

廉价感情. 提交于 2019-12-01 21:45:25
1 #include<iostream> 2 #include <opencv2\opencv.hpp> 3 using namespace cv; 4 using namespace std; 5 #include "test.h" 6 7 int main() 8 { 9 Mat img = imread("1.png"); 10 Mat gray; 11 cvtColor(img, gray, CV_BGR2GRAY); 12 threshold(gray, gray, 0, 255, CV_THRESH_BINARY); 13 // digits.png为2000 * 1000,其中每个数字的大小为20 * 20, 14 // 总共有5000((2000*1000) / (20*20))个数字,类型为[0~9], 15 // [0~9]10个数字每个数字有5000/10 = 500个样本 16 // 对其分割成单个20 * 20的图像并序列化成(转化成一个一维的数组) 17 int side = 20; 18 int m = gray.rows / side; 19 int n = gray.cols / side; 20 Mat data, labels; 21 for (int i = 0; i < m; i++) { 22 23 int offsetRow = i *

最新检测程序

天涯浪子 提交于 2019-12-01 07:11:20
# -*- coding: utf-8 -*-import cv2 as cvimport numpy as npfrom matplotlib import pyplot as pltimport cv2## *针孔 zhenkong Min<1 gate>=0.6 Min>1 gate>=0.8 12张# *起粒 qili 5 Min<1 Max<50 gate<=0.6 Min<1 Max>50 gate>=0.4 5张 选 0.4# *挂伤 guashang Max<20 0.4<gate<=0.5 20<Max<40 0.1<gate<=0.4 Max>40 gate<=0.2# *挂流 gualiu Min<1 Max<50 0.2<gate<=0.5 选0.4#C:/Users/Administrator/Desktop/漆膜数据集样本/qimoshujuji/困难的分割图片/gualiu/#guashang qili zhenkongimg = cv.imread('C:/Users/Administrator/Desktop/qimoshujujiance/qimoshujuji/hard_images/00.jpg',0)rows, cols = img.shapecrow,ccol = rows//2 , cols//2im_copy_max=np.zeros