Streaming Live View
Live view function enables us to get images of every frame without capturing.
While getting the sequence of live view images, we can still access to all shooting functions without any restriction.
You can use #start_liveview_thread
to create new thread to start streaming live view images to your client PC.
#start_liveview_thread
receives a block that is called each time the new live view image arrives.
The block parameter is the LiveviewImage
class instance, which contains a sequence number, timestamp, and JPEG data.
This example continues to save live view images to the current directory.
th = cam.start_liveview_thread do |img|
filename = "#{img.sequence_number}.jpg"
File.write filename, img.jpeg_data
puts "wrote #{filename}."
end
th.join
Live view frame information provides the information of the several frames, e.g. focus frames, tracking frames and face frames. If your camera supports Liveview Frame API group, live view frame information is automatically enabled.
You can get live view frame information as LiveviewFrameInformation
class instance by the second block parameter.
This example continues to take a picture only if a face detection frame exists.
face_detected = false
th = cam.start_liveview_thread do |img, info|
face_frame = info.frames.find { |f| f.category == 4 }
if face_frame
puts " top-left = (#{face_frame .top_left.x}, #{face_frame .top_left.y})"
puts " bottom-right = (#{face_frame .bottom_right.x}, #{face_frame .bottom_right.y})"
face_detected = true
else
puts 'No face!'
face_detected = false
end
end
loop do
if face_detected
cam.capture_still
end
sleep 1
end