Skip to content

Instantly share code, notes, and snippets.

@PeaceAndHiLight
Last active January 5, 2016 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeaceAndHiLight/edccc845daf5246d34bc to your computer and use it in GitHub Desktop.
Save PeaceAndHiLight/edccc845daf5246d34bc to your computer and use it in GitHub Desktop.
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
Copy link
Author

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