Here is the code so its clear incase you really care =P
from PIL import Image
from PIL import ImageGrab
import time
capturedFrames = 100
count = 0
print "\nInitializing Engine..."
newView = ImageGrab.grab()
print "Engine Initilized Successfully!"
raw_input("Press any key to begin...")
print "\nInitializing capture cycle..."
startClock = time.clock()
for i in range(capturedFrames): # Here is the loop I was timing that I commented is extremely slow using the method you suggested. It does work however.
oldView = newView
newView = ImageGrab.grab()
if oldView.tostring() != newView.tostring():
count = count + 1
endClock = time.clock()
totalTime = endClock - startClock
calculatedFPS = capturedFrames / totalTime
horRes = str(newView.getbbox()[2])
verRes = str(newView.getbbox()[3])
print "Frame Resolution : %sx%s" % (horRes.rjust(4), verRes.rjust(4))
print "Frames Captured : %s" % str(capturedFrames).rjust(9)
print "Capture Time (sec) : %s" % str(totalTime)[:4].rjust(9)
print "Calculated FPS : %s" % str(calculatedFPS)[:4].rjust(9)
print "Changes Registered : %s" % str(count).rjust(9)
raw_input("\nPress Any Key...")
On 11/8/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
Chris Hengge wrote:
> alist = difference(image1,image2)
> a = [b for b in alist.getdata() if b != (0,0,0)]
> if len(a) != 0:
> print "Not the same"
>
> is much slower then (9x)
>
> if im1.tostring() != im2.tostring()
> print "something changed!"
>
> This loop itself is fairly slow by itself though.. I'm going to try
> and see if there is a faster way.
Chris,
are you sure you know what a loop is?
The only loop here is in the list comprehension.
'if' is not a loop.
'for' and 'while' are.
In computer science, it's important to be clear in your use of terminology.
It makes sense that my example was slow.
I didn't really think to try converting them to strings.
Any time you're trying to compare pixel values, it's going to take a while,
cause remember, a 1024X768 image has 786,432 different pixels.
I think your tostring comparison may be your best bet.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor