Remove python stuff to swap over to C++
This commit is contained in:
153
.gitignore
vendored
153
.gitignore
vendored
@@ -1,133 +1,38 @@
|
|||||||
# Byte-compiled / optimized / DLL files
|
# Prerequisites
|
||||||
__pycache__/
|
*.d
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
*.so
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
# Distribution / packaging
|
# Fortran module files
|
||||||
.Python
|
*.mod
|
||||||
build/
|
*.smod
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
pip-wheel-metadata/
|
|
||||||
share/python-wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# PyInstaller
|
# Compiled Static libraries
|
||||||
# Usually these files are written by a python script from a template
|
*.lai
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
*.la
|
||||||
*.manifest
|
*.a
|
||||||
*.spec
|
*.lib
|
||||||
|
|
||||||
# Installer logs
|
# Executables
|
||||||
pip-log.txt
|
*.exe
|
||||||
pip-delete-this-directory.txt
|
*.out
|
||||||
|
*.app
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.nox/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
*.py,cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
db.sqlite3
|
|
||||||
db.sqlite3-journal
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# IPython
|
|
||||||
profile_default/
|
|
||||||
ipython_config.py
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
.python-version
|
|
||||||
|
|
||||||
# pipenv
|
|
||||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
||||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
||||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
||||||
# install all needed dependencies.
|
|
||||||
#Pipfile.lock
|
|
||||||
|
|
||||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
||||||
__pypackages__/
|
|
||||||
|
|
||||||
# Celery stuff
|
|
||||||
celerybeat-schedule
|
|
||||||
celerybeat.pid
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Environments
|
|
||||||
.env
|
|
||||||
.venv
|
|
||||||
env/
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
env.bak/
|
|
||||||
venv.bak/
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
.dmypy.json
|
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
||||||
|
|
||||||
|
# Images taken by the camera
|
||||||
images/
|
images/
|
||||||
|
|
||||||
|
# VSCode stuff
|
||||||
.vscode
|
.vscode
|
||||||
13
README.md
13
README.md
@@ -1,13 +1,2 @@
|
|||||||
# PiCamera
|
# PiCamera
|
||||||
Camera for Raspberry Pi
|
Camera for Raspberry Pi in C++ :)
|
||||||
|
|
||||||
## How to run
|
|
||||||
Either:
|
|
||||||
```
|
|
||||||
chmod +x ./start.sh
|
|
||||||
./start.sh
|
|
||||||
```
|
|
||||||
Or:
|
|
||||||
```
|
|
||||||
python3 src/main.py
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
pygame==1.9.6
|
|
||||||
pygame-gui==0.5.7
|
|
||||||
36
src/main.py
36
src/main.py
@@ -1,36 +0,0 @@
|
|||||||
import picamui
|
|
||||||
import picam
|
|
||||||
|
|
||||||
def main():
|
|
||||||
captureResolution = (1280, 1024)
|
|
||||||
captureDirectory = "./images"
|
|
||||||
captureExtension = "jpg"
|
|
||||||
|
|
||||||
# Setup UI
|
|
||||||
ui = picamui.PiCamUi()
|
|
||||||
ui.createUi()
|
|
||||||
|
|
||||||
# Setup camera
|
|
||||||
cam = picam.PiCam()
|
|
||||||
cam.setPreviewResolution(ui.getScreenResolution())
|
|
||||||
captureResolution = cam.getMaxResolution()
|
|
||||||
|
|
||||||
loop = True
|
|
||||||
while loop:
|
|
||||||
rgb = cam.getPreviewFrame()
|
|
||||||
ui.updatePreview(rgb, cam.getPreviewResolution())
|
|
||||||
ui.update()
|
|
||||||
|
|
||||||
uiEvents = ui.getEvents()
|
|
||||||
for event in uiEvents:
|
|
||||||
if event == "keyDownEscape" or event == "pygameQuit" or event == "btnExitPressed":
|
|
||||||
loop = False
|
|
||||||
elif event == "btnTakePressed":
|
|
||||||
cam.capture(captureResolution, captureDirectory, captureExtension)
|
|
||||||
else:
|
|
||||||
print("Unknown event {}".format(event))
|
|
||||||
ui.cleanup()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
44
src/picam.py
44
src/picam.py
@@ -1,44 +0,0 @@
|
|||||||
import picamera
|
|
||||||
import io
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
class PiCam:
|
|
||||||
camera = None
|
|
||||||
resPreview = (640, 480)
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.camera = picamera.PiCamera()
|
|
||||||
|
|
||||||
def setCamResolution(self, res):
|
|
||||||
self.camera.resolution = res
|
|
||||||
|
|
||||||
def setPreviewResolution(self, res):
|
|
||||||
self.resPreview = res
|
|
||||||
self.setCamResolution(self.resPreview)
|
|
||||||
|
|
||||||
def getPreviewResolution(self):
|
|
||||||
return self.resPreview
|
|
||||||
|
|
||||||
def getMaxResolution(self):
|
|
||||||
return (self.camera.MAX_RESOLUTION.width, self.camera.MAX_RESOLUTION.height)
|
|
||||||
|
|
||||||
def capture(self, res, directory, extension):
|
|
||||||
now = datetime.now()
|
|
||||||
strNow = now.strftime("%d-%m-%Y %H-%M-%S")
|
|
||||||
self.setCamResolution(res)
|
|
||||||
self.camera.capture("./{0}/{1}.{2}".format(directory, strNow, extension))
|
|
||||||
self.setCamResolution(self.resPreview)
|
|
||||||
|
|
||||||
def getPreviewFrame(self):
|
|
||||||
rgb = bytearray(self.getPreviewResolution()[0] * self.getPreviewResolution()[1] * 3)
|
|
||||||
stream = io.BytesIO()
|
|
||||||
self.camera.capture(stream, use_video_port=True, format="rgb")
|
|
||||||
stream.seek(0)
|
|
||||||
stream.readinto(rgb)
|
|
||||||
stream.close()
|
|
||||||
|
|
||||||
return rgb
|
|
||||||
|
|
||||||
def cleanup(self):
|
|
||||||
self.camera.close()
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import pygame
|
|
||||||
import pygame_gui
|
|
||||||
|
|
||||||
class PiCamUi:
|
|
||||||
screen = None
|
|
||||||
guiManager = None
|
|
||||||
clock = None
|
|
||||||
uiElements = []
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
pygame.init()
|
|
||||||
# Set the cursor to invisible. We use a transparent cursor for this as set_visible breaks the touch screen
|
|
||||||
pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
|
|
||||||
self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # (0, 0) means same as display resolution
|
|
||||||
|
|
||||||
def createUi(self):
|
|
||||||
self.guiManager = pygame_gui.UIManager((self.screen.get_width(), self.screen.get_height()))
|
|
||||||
self.clock = pygame.time.Clock()
|
|
||||||
|
|
||||||
self.createUiElements()
|
|
||||||
|
|
||||||
def createUiElements(self):
|
|
||||||
btnTake = {
|
|
||||||
"name": "btnTake",
|
|
||||||
"element": pygame_gui.elements.UIButton(
|
|
||||||
relative_rect = pygame.Rect((720, 200), (80, 80)),
|
|
||||||
text = "Take",
|
|
||||||
manager = self.guiManager
|
|
||||||
)
|
|
||||||
}
|
|
||||||
self.uiElements.append(btnTake)
|
|
||||||
|
|
||||||
btnExit = {
|
|
||||||
"name": "btnExit",
|
|
||||||
"element": pygame_gui.elements.UIButton(
|
|
||||||
relative_rect=pygame.Rect((760, 440), (40, 40)),
|
|
||||||
text='X',
|
|
||||||
manager=self.guiManager
|
|
||||||
)
|
|
||||||
}
|
|
||||||
self.uiElements.append(btnExit)
|
|
||||||
|
|
||||||
def updatePreview(self, rgb, res):
|
|
||||||
img = pygame.image.frombuffer(rgb[0:(res[0] * res[1] * 3)], res, 'RGB')
|
|
||||||
img = pygame.transform.scale(img, (self.screen.get_width(), self.screen.get_height()))
|
|
||||||
|
|
||||||
if img:
|
|
||||||
self.screen.blit(img, (0, 0))
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.guiManager.draw_ui(self.screen)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
def cleanup(self):
|
|
||||||
pygame.display.quit()
|
|
||||||
|
|
||||||
def getEvents(self):
|
|
||||||
events = []
|
|
||||||
time_delta = self.clock.tick(30)/1000.0
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.KEYDOWN:
|
|
||||||
if event.key == pygame.K_ESCAPE:
|
|
||||||
events.append("keyDownEscape")
|
|
||||||
elif event.type == pygame.QUIT:
|
|
||||||
events.append("pygameQuit")
|
|
||||||
elif event.type == pygame.USEREVENT:
|
|
||||||
if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
|
|
||||||
for element in self.uiElements:
|
|
||||||
if event.ui_element == element.get("element"):
|
|
||||||
events.append("{}Pressed".format(element.get("name")))
|
|
||||||
self.guiManager.process_events(event)
|
|
||||||
self.guiManager.update(time_delta)
|
|
||||||
|
|
||||||
return events
|
|
||||||
|
|
||||||
def getScreenResolution(self):
|
|
||||||
return (self.screen.get_width(), self.screen.get_height())
|
|
||||||
Reference in New Issue
Block a user