Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpenCV and Numpy ImageRead
#coding: utf-8
import cv2
import numpy as np
# readImage
img = cv2.imread('beatles_forsale.jpg')
print type(img)
pixelValue = img[10, 20]
print type(pixelValue)
print 'pixelValue = ' + str(pixelValue)
blue = img[10, 20, 0]
green = img[10, 20, 1]
red = img[10, 20, 2]
print type(blue)
print 'blue = ' + str(blue)
print 'green = ' + str(green)
print 'red = ' + str(red)
# Numpy array method
blue = img.item(10, 20, 0)
green = img.item(10, 20, 1)
red = img.item(10, 20, 2)
print type(blue)
print 'blue = ' + str(blue)
print 'green = ' + str(green)
print 'red = ' + str(red)
# Modify
img[10, 20, 0] = 100
print img[10, 20, 0]
@PeaceAndHiLight

This comment has been minimized.

Copy link
Owner Author

PeaceAndHiLight commented Jan 5, 2016

Read Image In OpenCV and GetPixelValue By Numpy

simple access way to get pixel value by numpy method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.