Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement raw frame access for python #6

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build
.vscode

*.exe
*.o
*.d
Expand All @@ -8,3 +11,8 @@
*.jtag
*.swp
*.swo
*.so

pixy.py
*.pyc
*.cxx
50 changes: 50 additions & 0 deletions scripts/build_python3_demos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

function WHITE_TEXT {
printf "\033[1;37m"
}
function NORMAL_TEXT {
printf "\033[0m"
}
function GREEN_TEXT {
printf "\033[1;32m"
}
function RED_TEXT {
printf "\033[1;31m"
}

WHITE_TEXT
echo "########################################################################################"
echo "# Building Get Blocks Python (SWIG) Demo... #"
echo "########################################################################################"
NORMAL_TEXT

uname -a

TARGET_BUILD_FOLDER=../build

mkdir $TARGET_BUILD_FOLDER
mkdir $TARGET_BUILD_FOLDER/python_demos

cd ../src/host/libpixyusb2_examples/python_demos

swig -c++ -python pixy.i
python3 setup.py build_ext --inplace -D__LINUX__

# For python3 only, the name of shared lib contains arch name, we need to rename it
mv _pixy.*.so _pixy.so

if [ -f ../../../../build/python_demos/_pixy.so ]; then
rm ../../../../build/python_demos/_pixy.so
fi

cp * ../../../../build/python_demos

if [ -f ../../../../build/python_demos/_pixy.so ]; then
GREEN_TEXT
printf "SUCCESS "
else
RED_TEXT
printf "FAILURE "
fi
echo ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from PIL import Image
import numpy as np

import pixy
from pixy import *

pixy.init()
pixy.change_prog('color_connected_components')

frame_width = 316
frame_height = 208

for i in range(5):
raw_frame = pixy.video_get_raw_frame(frame_width*frame_height*3)
img = Image.fromarray(raw_frame.reshape(frame_height, frame_width,3))
img.save('pixy' + str(i) + '.bmp')
Loading