Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy
- import time
- import picamera
- import cv2
- with picamera.PiCamera() as camera:
- camera.resolution = (1280, 720)
- camera.framerate = 30
- # Wait for analog gain to settle on a higher value than 1
- while camera.analog_gain <= 1:
- time.sleep(0.1)
- # Now fix the values
- camera.shutter_speed = camera.exposure_speed
- camera.exposure_mode = 'off'
- g = camera.awb_gains
- camera.awb_mode = 'off'
- assert isinstance(g, object)
- camera.awb_gains = g
- #Capture the actual image we want to test
- camera_capture = get_image()
- file = "/home/pi/Desktop/test_image.jpg"
- cv2.imwrite(file, camera_capture)
- # You'll want to release the camera, otherwise you won't be able to
- #create a new
- # capture object until your script exits
- del (camera)
- #read the image captured by the camera
- myimg = cv2.imread('test_image.jpg')
- #converts the image pixels from RGB to LAB
- lab_image = cv2.cvtColor(myimg, cv2.COLOR_BGR2LAB)
- #split the channels of of the converted LAB color values
- l_channel,a_channel,b_channel = cv2.split(lab_image)
- #gets the average value of L
- avg_color_per_row_l = numpy.average(l_channel, axis=0)
- avg_color_l = numpy.average(avg_color_per_row_l, axis = 0)
- print ('The L* value is : ',avg_color_l)
Add Comment
Please, Sign In to add comment