<<python computer vision with opencv>> chapter 2
2014-05-27 11:17
495 查看
import cv2 import numpy import os # Make an array of 120,000 random bytes. randomByteArray = bytearray(os.urandom(120000)) flatNumpyArray = numpy.array(randomByteArray) # Convert the array to make a 400x300 grayscale image. grayImage = flatNumpyArray.reshape(300, 400) # Assignment grayImage[0, 0] = 0 # grayImage.setitem([0, 1], 128) # AttributeError: 'numpy.ndarray' object has no attribute 'setitem' # Write image cv2.imwrite('RandomGray.png', grayImage) # Convert the array to make a 400x100 color image. bgrImage = flatNumpyArray.reshape(100, 400, 3) # 24-bit BGR image with a Red pixel in the upper-left corner bgrImage[0, 0] = [0, 0, 255] # [0, 0, 255] from left to right --> 0: Blue; 0: Green; 0: Red cv2.imwrite('RandomColor.png', bgrImage)
CameraCaptureFrames write to avi video
import cv2
cameraCapture = cv2.VideoCapture(0)
fps = 1 # an assumption
size = (int(cameraCapture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)),
int(cameraCapture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)))
videoWriter = cv2.VideoWriter('MyOutputVid.avi',
cv2.cv.CV_FOURCC('I','4','2','0'),
fps, size)
success, frame = cameraCapture.read()
numFramesRemaining = 10 * fps - 1
while success and numFramesRemaining > 0:
videoWriter.write(frame)
success, frame = cameraCapture.read()
numFramesRemaining -= 1
相关文章推荐
- OpenCV新书<Mastering OpenCV with Practical Computer Vision Projects>
- 人脸识别之人眼定位、人脸矫正、人脸尺寸标准化---<Mastering OpenCV with Practical Computer Vision Projects >
- 人脸识别之人眼定位、人脸矫正、人脸尺寸标准化---<Mastering OpenCV with Practical Computer Vision Projects >
- Opencv2 computer vision application programming cookbook<一>
- Opencv2 computer vision application programming cookbook<四>
- Opencv2 computer vision application programming cookbook<三>
- 《OpenCV Computer Vision with Python》pdf
- [翻译]<Web Scraping with Python>Chapter 1.你的第一个网络爬虫
- [翻译]<Web Scraping with Python>Chapter 3.开始爬行吧
- Opencv2 computer vision application programming cookbook<七>
- [翻译]<Web Scraping with Python>Chapter 0.前言
- [翻译]<Web Scraping with Python>Chapter 2.高级HTML解析
- OpenCV学习笔记(六十二)——《OpenCV Computer Version with Python》阅读摘要
- 整理《Mastering OpenCV with Practical Computer Vision Projects》中第5章用SVM和神经网络进行车牌识别操作流程
- <Natural Language Processing with Python>学习笔记一
- 翻译:Mastering OpenCV with Practical Computer Vision Projects(第8章)(一)
- <Chapter 2>2-2-2.开发Python应用(Developing a Python App)
- szeliski——computer vision algorithm and application<一>introduction
- 网络爬虫 HTML的高级解析 <web scraping with python>第二章
- [新书推荐]A Practical Introduction to Computer Vision with OpenCV