Last active
January 5, 2016 12:32
-
-
Save PeaceAndHiLight/edccc845daf5246d34bc to your computer and use it in GitHub Desktop.
OpenCV and Numpy ImageRead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read Image In OpenCV and GetPixelValue By Numpy
simple access way to get pixel value by numpy method.