Learning to script, having file permission errors

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Learning to script, having file permission errors

#1

Post by tmnathe »

Error - Single frame capture failed - A required privilege not found.

I'm learning how to do Python and not doing a good job at it either.
So far, this is the script that I'm cobbling together. It works after a fashion, but I keep getting the above error. The file permissions within Windows are all set properly, so what am I missing here?

I'm also getting this error for this bit -
SharpCap.SelectedCamera.Controls.OutputFormat.Value = 'PNG files (*.png)'
Traceback (most recent call last):
File "<string>", line 5, in <module>
AttributeError: 'NoneType' object has no attribute 'Controls'

My simplistic code. This was copied and pasted from various sources that I could find.

===========================================================================

SharpCap.SelectedCamera = SharpCap.Cameras.Find(lambda x:x.DeviceName == "QSI Camera")

SharpCap.Wheels.SelectedWheel.Position = 1 #LUM

SharpCap.SelectedCamera.Controls.OutputFormat.Value = 'PNG files (*.png)'

SharpCap.SelectedCamera.Controls.Exposure.Value = 0.02 #seconds

SharpCap.SelectedCamera.CaptureSingleFrameTo("c:\SC_test\test.png")

# SharpCap.Transforms.SelectedTransform = AutoStretch (not sure if this one is correct)
User avatar
admin
Site Admin
Posts: 13349
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK
Contact:

Re: Learning to script, having file permission errors

#2

Post by admin »

Hi,

the NoneType error indicates that there is most likely no camera open at the point that you are trying to access the controls - you need to open a camera before you can do anything with it. This may be happening because your script is moving on too quickly after the line that opens the camera, so that by the time it tries to set the output to PNG format, the camera is not ready. I would suggest adding a delay at that point.

I think the file problem is todo with the '\' character in the path. In python strings, the backslash character is primarily used to make special characters in conjunction with the following character, so you are trying to save to a file called 'c<special character>C_test<tab character>test.png'. You need to change the code to read

Code: Select all

SharpCap.SelectedCamera.CaptureSingleFrameTo("c:\\SC_test\\test.png")
use a double backslash where you really want one backslash in the string to fix this.

cheers,

Robin
tmnathe
Posts: 21
Joined: Fri Jul 29, 2022 4:13 am

Re: Learning to script, having file permission errors

#3

Post by tmnathe »

Thanks, Robin!

Adding the extra backslash did the trick!
I also added a 5 second delay after selecting the camera and another 5 second delay after the filter selection.
It seems the program really likes to wait that long.

Now, I'm off to do more dangerous learning!
Post Reply