<< return to Pixycam.com

Get_blocks py 3

when i am useing the get_blocks or any other command with the consule command it works great but i when i am trying to active it from the file itself it says some weard stuff, like that i need to add brackets at lines 31 and 34, and than it says that it have problams with the pixy.py files. (i am useing rusberry pi 3 and pixy 1)
what can i do?

Hello,
I’m having trouble understanding your question. Please consider that I don’t know what’s in lines 31 and 34, what file you’re referring to, and I don’t know what commands(?) are failing or how they are failing. Please describe in more detail.

Edward

from pixy import *
from ctypes import *

# Pixy Python SWIG get blocks example #

print ("Pixy Python SWIG Example -- Get Blocks")

# Initialize Pixy Interpreter thread #
pixy_init()

class Blocks (Structure):
_fields_ = [ ("type", c_uint),
           ("signature", c_uint),
           ("x", c_uint),
           ("y", c_uint),
           ("width", c_uint),
           ("height", c_uint),
           ("angle", c_uint) ]

blocks = BlockArray(100)
frame  = 0

# Wait for blocks #
while 1:

count = pixy_get_blocks(100, blocks)

 if count > 0:
# Blocks found #
print 'frame %3d:' % (frame)
frame = frame + 1
for index in range (0, count):
  print '[BLOCK_TYPE=%d SIG=%d X=%3d Y=%3d WIDTH=%3d HEIGHT=%3d]' % `Preformatted text`(blocks[index].type, blocks[index].signature, blocks[index].x, blocks[index].y, blocks[index].width, blocks[index].height)

sould be lines 30 and 33 actualy, i dont know why but when i am putting brackets like this:
print (‘frame %3d:’ % (frame))
it have no problem, exapt that it start reffering to ton of lines from pixy.py (that he is probably using)

Are you using python3?

Yes i am useing python 3

just tried to run it with py 2.7, work

Hello,
The latest code in github runs under Python3. Thanks for your patience!

Edward