Hi,
I was wondering if it is possible to accomplish some processing on live image? I have tried some simple things but it says image is locked for processing.
image = Zen.Acquisition.StartLive()
Zen.Application.ActiveDocument = image
SomeProcessing(image)
Best regards
Fredrik Olsson
Possible to process live image?
Hello Fredrik Olsson,
you will need AcquireImage() as you can only process the snapped Image.
Refer to the following code:
you will need AcquireImage() as you can only process the snapped Image.
Refer to the following code:
Code: Select all
#######################################################
## A C Q U I S I T I O N
##
## Macro name: Demo - Snap and save user defined number of images
##
## Required demo files: no
##
## Required module/licence: no
##
## ENTER PATH, SAMPLE NAME, NUMBER OF IMAGES, IMAGE TYPE
## SNAP IMAGES IN A LOOP, BURN IN SCALEBAR FOR NON-CZI IMAGES,
## SAVE IMAGES AUTOMATICALLY
##
#######################################################
##
##
## activate IO library
from System.IO import Directory
##
## create setup dialog
window = ZenWindow()
Images = Zen.Application.Environment.GetFolderPath(ZenSpecialFolder.Images)
window.AddFolderBrowser('destpath','DestinationFolder: ',Images)
window.AddCheckbox('chkScale','Snap with scalebar ',False)
window.AddTextBox('tval','Enter sample name:','sample')
window.AddDropDown('ddval','Image type: ',['.CZI','.JPG','.JPEG','.BMP','.TIF','.TIFF'],0)
window.AddIntegerRange('ival','Number of images:',1,1,50)
## do setup
result=window.Show()
## check, if Cancel button was clicked
if result.HasCanceled == True:
sys.exit('Macro aborted with Cancel!')
## get string name of path
path = result.GetValue('destpath')
## Check, if path exists
if (Directory.Exists(path)== False):
strMessage = 'Path: ' + path + ' does not exist!\nRestart macro and select an existing path!'
sys.exit(strMessage)
## get sample name
sampleName = result.GetValue('tval')
## check, if sample name is not empty
sampleName = sampleName.Trim()
#if sampleName != "":
if sampleName == "":
strMessage = 'Sample name is empty!\nRestart macro and enter a sample name!'
sys.exit(strMessage)
## Get image number, image type, scale
imageNumber = result.GetValue('ival')
imageType = str(result.GetValue('ddval')).strip()
scale = result.GetValue('chkScale')
##
## IMAGES
## loop over number of images
count = 0
for i in range(0,imageNumber):
## Show live image
live = Zen.Acquisition.StartLive()
Zen.Application.ActiveDocument = live
## Set exposure time (AutoExposure)
Zen.Acquisition.AutoExposure()
## Show pause dialog
Zen.Application.Pause("Search field of interest\nand focus image number: " + str(i+1) + " of " + str(imageNumber))
## Snap image
image = Zen.Acquisition.AcquireImage()
Zen.Application.ActiveDocument = image
## Define sample name and image number
newFileName = sampleName + str(i+1) + imageType
newPathAndFile = path + "\\" + newFileName
## insert scalebar
if scale == True:
image.InsertDefaultScaleBarGraphic()
if imageType <> '.CZI':
## Burn in scalebar for non-CZI images
AnnoImage = image.BurnInGraphics()
## Save the image with scalebar automatically
Zen.Application.Save(AnnoImage,newPathAndFile)
AnnoImage.Close()
if imageType == '.CZI':
Zen.Application.Save(image,newPathAndFile)
elif scale == False:
## Save the image automatically
Zen.Application.Save(image,newPathAndFile)
## Close image
image.Graphics.Clear()
image.Close()
count = count + 1
## Close live image
Zen.Acquisition.StopLive()
##
## end of loop
## IMAGES
##
## Show message
strMessage = str(count) + ' Images are saved in: \n' + path
Zen.Application.Pause(strMessage)
##
#######################################################
-
- Posts: 2
- Joined: Wed Aug 23, 2023 4:08 am
- Contact:
Re: Possible to process live image?
Maybe you need to make sure that the picture isn't being used by any other program or process to fix this problem. Close any programs that might be using the picture, and then try the processing again.
Life is different aspects.