Guest User

Untitled

a guest
Mar 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import sys
  2. import numpy
  3. import time
  4. import picamera
  5. import cv2
  6.  
  7. with picamera.PiCamera() as camera:
  8. camera.resolution = (1280, 720)
  9. camera.framerate = 30
  10. # Wait for analog gain to settle on a higher value than 1
  11. while camera.analog_gain <= 1:
  12. time.sleep(0.1)
  13. # Now fix the values
  14. camera.shutter_speed = camera.exposure_speed
  15. camera.exposure_mode = 'off'
  16. g = camera.awb_gains
  17. camera.awb_mode = 'off'
  18. assert isinstance(g, object)
  19. camera.awb_gains = g
  20.  
  21. #Capture the actual image we want to test
  22. camera_capture = get_image()
  23. file = "/home/pi/Desktop/test_image.jpg"
  24.  
  25.  
  26. cv2.imwrite(file, camera_capture)
  27.  
  28. # You'll want to release the camera, otherwise you won't be able to
  29. #create a new
  30. # capture object until your script exits
  31. del (camera)
  32.  
  33.  
  34. #read the image captured by the camera
  35. myimg = cv2.imread('test_image.jpg')
  36.  
  37. #converts the image pixels from RGB to LAB
  38. lab_image = cv2.cvtColor(myimg, cv2.COLOR_BGR2LAB)
  39.  
  40. #split the channels of of the converted LAB color values
  41. l_channel,a_channel,b_channel = cv2.split(lab_image)
  42.  
  43. #gets the average value of L
  44. avg_color_per_row_l = numpy.average(l_channel, axis=0)
  45. avg_color_l = numpy.average(avg_color_per_row_l, axis = 0)
  46. print ('The L* value is : ',avg_color_l)
Add Comment
Please, Sign In to add comment