Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Hi All,

 

I am looking for a bit of free software that will allow me to use either a DSLR or a webcam to take pictures using the computer and then name the file. we have a large number of new Staff / Students joining us and we need to add a picture of them to the system however we need a way of knowing which picture is which person. so i was hoping to find a bit of software that will show you the live feed from the camera and then let you take a picture and name the file before it gets saved.

 

does anybody know of anything?

 

Many thanks

Posted
does anybody know of anything?

 

Sure - you can control a USB camera from Python via the WIA protocol. The code below is taken from a utility we use at Christmas to take photos of the children with Santa, then add a border around the picture and print a Christmas card. I've trimmed out the bits that edit the image. This is run on a Windows machine running ActiveState Python, you might need to make some changes for it run with the standard Python distribution (i.e. I can;t remember if win32com.client is included with Python on Windows as standard or not)

 

import os
import time
import Image
import random
import win32com.client

rootPath = "C:\Camera\pics"

MY_CAMERA="D5100"
WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
WIA_COMMAND_TAKE_PICTURE="{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"

validRandomChars = "1234567890"

def generateRandomString():
result = ""
for pl in range(0,5):
	result = result + validRandomChars[random.randint(0,len(validRandomChars)-1)]
return(result)

def addZeros(theString, theLength):
result = theString
while len(result) < theLength:
	result = "0" + result
return(result)

# Save an image accquired via WIA to a file.
def saveImage(image, imageIndex):
filename = addZeros(str(imageIndex),5) + "-" + generateRandomString() + ".jpg"
while filename in os.listdir(rootPath):
	filename = generateRandomString()
image.SaveFile(rootPath + os.sep + filename)
return(filename)

# Checks the camera attached via the WIA protocol (Windows's implemenattion of PTP) and grabs
# any new photos as they appear.
def acquireImage():
# Find the camera
devman=win32com.client.Dispatch("WIA.DeviceManager")
for info in devman.DeviceInfos:
	for prop in info.Properties:
		if prop.Name=="Name" and prop.Value==MY_CAMERA:
			dev = info.Connect()
			
previousCount = dev.Items.count
while True == True:
	currentCount = dev.Items.count
	for pl in range(previousCount, currentCount):
		imagePath = saveImage(dev.Items[pl].Transfer(WIA_IMG_FORMAT_PNG), pl)
	previousCount = currentCount
	time.sleep(1)
	
acquireImage()

  • Thanks 1
Posted
also some dlsr's allow you to do this native with their software my eos 70d does i can control it via the wifi from my pc / android/ios good for time lapse stuff must set pc to take an image every x mins
Posted
Or, rather than just taking a steam hammer to crack a nut, use a regular digital camera and write down the names in the order in which they were taken ... just a thought.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...