8
8
import tempfile
9
9
import time
10
10
from tempfile import TemporaryDirectory
11
- import uuid
12
11
13
12
from pydantic import BaseModel , BeforeValidator , RootModel
14
13
@@ -579,7 +578,7 @@ def snap_image(self) -> ArrayModel:
579
578
def capture_array (
580
579
self ,
581
580
stream_name : Literal ["main" , "lores" , "raw" , "full" ] = "main" ,
582
- wait : Optional [float ] = None ,
581
+ wait : Optional [float ] = 0.9 ,
583
582
) -> ArrayModel :
584
583
"""Acquire one image from the camera and return as an array
585
584
@@ -588,7 +587,9 @@ def capture_array(
588
587
binary image formats will be added in due course.
589
588
590
589
stream_name: (Optional) The PiCamera2 stream to use, should be one of ["main", "lores", "raw", "full"]. Default = "main"
591
- wait: (Optional, float) Set a timeout in seconds. A TimeoutError is raised if this time is exceeded during capture. Default = None
590
+ wait: (Optional, float) Set a timeout in seconds.
591
+ A TimeoutError is raised if this time is exceeded during capture.
592
+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
592
593
"""
593
594
if stream_name == "full" :
594
595
with self .picamera (pause_stream = True ) as picam2 :
@@ -603,19 +604,24 @@ def capture_raw(
603
604
states_getter : GetThingStates ,
604
605
get_states : bool = True ,
605
606
get_processing_inputs : bool = True ,
607
+ wait : Optional [float ] = 0.9 ,
606
608
) -> RawImageModel :
607
609
"""Capture a raw image
608
610
609
611
This function is intended to be as fast as possible, and will return
610
612
as soon as an image has been captured. The output format is not intended
611
613
to be useful, except as input to `raw_to_png`.
612
-
614
+
615
+ wait: (Optional, float) Set a timeout in seconds.
616
+ A TimeoutError is raised if this time is exceeded during capture.
617
+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
618
+
613
619
When used via the HTTP interface, this function returns the data as a
614
620
`Blob` object, meaning it can be passed to another action without
615
621
transferring it over the network.
616
622
"""
617
623
with self .picamera () as cam :
618
- (buffer , ), parameters = cam .capture_buffers (["raw" ])
624
+ (buffer , ), parameters = cam .capture_buffers (["raw" ], wait = wait )
619
625
configuration = cam .camera_configuration ()
620
626
return RawImageModel (
621
627
image_data = RawBlob .from_bytes (buffer .tobytes ()),
@@ -757,6 +763,7 @@ def capture_jpeg(
757
763
self ,
758
764
metadata_getter : GetThingStates ,
759
765
resolution : Literal ["lores" , "main" , "full" ] = "main" ,
766
+ wait : Optional [float ] = 0.9 ,
760
767
) -> JPEGBlob :
761
768
"""Acquire one image from the camera as a JPEG
762
769
@@ -770,6 +777,10 @@ def capture_jpeg(
770
777
MJPEG stream and reconfigure the camera to capture a full
771
778
resolution image.
772
779
780
+ wait: (Optional, float) Set a timeout in seconds.
781
+ A TimeoutError is raised if this time is exceeded during capture.
782
+ Default = 0.9s, lower than the 1s timeout default in picamera yaml settings
783
+
773
784
Note that this always uses the image processing pipeline - to
774
785
bypass this, you must use a raw capture.
775
786
"""
@@ -781,7 +792,7 @@ def capture_jpeg(
781
792
# to reconfigure for these
782
793
if resolution in ("lores" , "main" ) and config [resolution ]:
783
794
with self .picamera () as cam :
784
- cam .capture_file (path , name = resolution , format = "jpeg" )
795
+ cam .capture_file (path , name = resolution , format = "jpeg" , wait = wait )
785
796
else :
786
797
if resolution != "full" :
787
798
logging .warning (
@@ -793,7 +804,7 @@ def capture_jpeg(
793
804
cam .start ()
794
805
cam .options ["quality" ] = 95
795
806
logging .info ("capturing" )
796
- cam .capture_file (path , name = "main" , format = "jpeg" , wait = 5 )
807
+ cam .capture_file (path , name = "main" , format = "jpeg" , wait = wait )
797
808
logging .info ("done" )
798
809
# After the file is written, add metadata about the current Things
799
810
exif_dict = piexif .load (path )
0 commit comments