码迷,mamicode.com
首页 > 编程语言 > 详细

Python OpenCV —— Modifying

时间:2016-09-29 07:37:27      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

  一些索引和修改图像像素点数据等的操作,可打印观察运行结果。

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 28 00:11:07 2016

@author: Administrator
"""

import cv2
import numpy as np
# length,588;width,468
img = cv2.imread(‘cute.jpg‘)

px = img[100,100]
print(px)

# accessing only blue pixel
# remember b,g,r
blue = img[100,100,0]
print(blue)

# modify the pixel
img[100,100] = [255,255,255]

# accesing RED value
p_item = img.item(10,10,2)

# modyfying RED value
pp_item = img.itemset((10,10,2),100)

# length width 3
p_shape = img.shape

# length*width*3
p_size = img.size

# data type
p_dtype = img.dtype

# Image ROI
# 将一块区域复制到另一区域
ball = img[280:340,330:390]
img[273:333,100:160] = ball
cv2.imshow(‘image‘,img)
k = cv2.waitKey(0)
if k == 27:
	cv2.destroyAllWindows()


# Splitting and Merging Image Channels
b,g,r = cv2.split(img)  # costly
img = cv2.merge((b,g,r))
b = img[:,:,0]  # blue

# make all the red pixels to zero
img[:,:,0] = 0

  

Python OpenCV —— Modifying

标签:

原文地址:http://www.cnblogs.com/buzhizhitong/p/5918498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!