0

im new to python and picamera. i was not able to capture an image using my code below. it gives me an error with the command camera.capture = get_image(). How can i fix this? also i would like my code to capture image but not overwrite the previous image captured by the camera. is it possible?

    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)
  • by the way, my code is used to get the average L* color values of an image – Ryan Mar 20 '18 at 15:38
  • 1
    It gives you "an error". What error? – larsks Mar 20 '18 at 18:13
  • i already fixed the issues :) but thanks for the comment :) but can i ask how can i capture multiple image with time intervals between captured images? – Ryan Mar 21 '18 at 6:55
  • edit your question – jsotola Mar 22 '18 at 19:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.