Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d01729c4b | ||
|
|
ac02297915 | ||
|
|
f63948b295 | ||
|
|
b3e4ba50a2 | ||
|
|
374d29629b | ||
|
|
0871c54dda | ||
|
|
a5e5f0f90d | ||
|
|
0b3ca62c4c | ||
|
|
a8ec8bdeab | ||
|
|
b4cb055995 | ||
|
|
cacd94da62 | ||
|
|
9b7daea177 | ||
|
|
0073d1f9c3 | ||
|
|
e750a4f523 | ||
|
|
130167b97d | ||
|
|
70198157fb | ||
|
|
0fcae4bdb1 | ||
|
|
169fe5e234 | ||
|
|
1a0e25bf83 | ||
|
|
97adf57e2e | ||
|
|
1d4ecdaa34 | ||
|
|
475a979c79 |
160
.gitignore
vendored
160
.gitignore
vendored
@@ -1,133 +1,43 @@
|
|||||||
# 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
|
# VSCode stuff
|
||||||
|
.vscode/
|
||||||
|
.devcontainer/
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Build folder
|
||||||
|
build/
|
||||||
|
|||||||
57
.gitlab-ci.yml
Normal file
57
.gitlab-ci.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# This file is a template, and might need editing before it works on your project.
|
||||||
|
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
||||||
|
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
||||||
|
# This specific template is located at:
|
||||||
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
|
||||||
|
|
||||||
|
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
|
||||||
|
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
|
||||||
|
# it uses echo commands to simulate the pipeline execution.
|
||||||
|
#
|
||||||
|
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
|
||||||
|
# Stages run in sequential order, but jobs within stages run in parallel.
|
||||||
|
#
|
||||||
|
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
|
||||||
|
|
||||||
|
image: debian:stable
|
||||||
|
|
||||||
|
stages: # List of stages for jobs, and their order of execution
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
build-job: # This job runs in the build stage, which runs first.
|
||||||
|
stage: build
|
||||||
|
tags:
|
||||||
|
- linux
|
||||||
|
before_script:
|
||||||
|
- apt update
|
||||||
|
- apt install -y clang cmake libgtkmm-3.0-dev clang-tidy
|
||||||
|
script:
|
||||||
|
- echo "Configuring"
|
||||||
|
- export CC=/usr/bin/clang
|
||||||
|
- export CXX=/usr/bin/clang++
|
||||||
|
- cmake -B build .
|
||||||
|
- echo "Building"
|
||||||
|
- cmake --build build
|
||||||
|
- echo "Compile complete."
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- build/src/JAMCS
|
||||||
|
|
||||||
|
# unit-test-job: # This job runs in the test stage.
|
||||||
|
# stage: test # It only starts when the job in the build stage completes successfully.
|
||||||
|
# tags:
|
||||||
|
# - linux
|
||||||
|
# script:
|
||||||
|
# - echo "Running unit tests... This will take about 60 seconds."
|
||||||
|
# - sleep 60
|
||||||
|
# - echo "Code coverage is 90%"
|
||||||
|
|
||||||
|
# deploy-job: # This job runs in the deploy stage.
|
||||||
|
# stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
|
||||||
|
# tags:
|
||||||
|
# - linux
|
||||||
|
# script:
|
||||||
|
# - echo "Deploying application..."
|
||||||
|
# - echo "Application successfully deployed."
|
||||||
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*,)
|
||||||
|
|
||||||
|
project(PiCamera)
|
||||||
|
|
||||||
|
# Find gtk+-4.0 library
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(GTK REQUIRED gtkmm-3.0)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
30
README.md
30
README.md
@@ -1,2 +1,28 @@
|
|||||||
# PiCamera
|
# JAMCS - James Camera Software
|
||||||
Camera for Raspberry Pi
|
Camera for Raspberry Pi in C++ :)
|
||||||
|
|
||||||
|
## To build
|
||||||
|
Requirements:
|
||||||
|
- CMake
|
||||||
|
- gtkmm 3.0
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
- clang-tidy
|
||||||
|
|
||||||
|
### Debian based
|
||||||
|
```bash
|
||||||
|
sudo apt install -y clang cmake libgtkmm-3.0-dev clang-tidy
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fedora
|
||||||
|
```bash
|
||||||
|
sudo dnf install clang cmake gtkmm30-devel clang-tools-extra
|
||||||
|
```
|
||||||
|
|
||||||
|
Then:
|
||||||
|
```bash
|
||||||
|
cmake -B build .
|
||||||
|
cmake --build build
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively you can just use the VSCode CMake Extension
|
||||||
|
|||||||
89
picam.py
89
picam.py
@@ -1,89 +0,0 @@
|
|||||||
import picamera
|
|
||||||
import pygame
|
|
||||||
import pygame_gui
|
|
||||||
import time
|
|
||||||
import io
|
|
||||||
import os
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
def setup_pygame():
|
|
||||||
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))
|
|
||||||
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # (0, 0) means same as display resolution
|
|
||||||
return screen
|
|
||||||
|
|
||||||
def setup_camera(screen):
|
|
||||||
camera = picamera.PiCamera()
|
|
||||||
camera.rotation = 90
|
|
||||||
return camera
|
|
||||||
|
|
||||||
def take_picture(camera, capture_resolution, directory):
|
|
||||||
now = datetime.now()
|
|
||||||
now_string = now.strftime("%d-%m-%Y %H-%M-%S")
|
|
||||||
print("Saving image to: \"./images/{0}.jpg\"".format(now_string))
|
|
||||||
camera.resolution = capture_resolution
|
|
||||||
camera.capture("./{0}/{1}.jpg".format(directory, now_string))
|
|
||||||
|
|
||||||
def set_cam_resolution(camera, resolution, framerate):
|
|
||||||
camera.resolution = resolution
|
|
||||||
camera.framerate = framerate
|
|
||||||
|
|
||||||
screen = setup_pygame()
|
|
||||||
camera = setup_camera(screen)
|
|
||||||
|
|
||||||
cam_viewfinder_resolution = (int(screen.get_width()), int(screen.get_height()))
|
|
||||||
cam_capture_resolution = (camera.MAX_RESOLUTION.width, camera.MAX_RESOLUTION.height)
|
|
||||||
cam_video_resolution = (1920, 1080)
|
|
||||||
|
|
||||||
cam_viewfinder_framerate = 15
|
|
||||||
cam_video_framerate = 30
|
|
||||||
|
|
||||||
set_cam_resolution(camera, cam_viewfinder_resolution, cam_viewfinder_framerate)
|
|
||||||
|
|
||||||
rgb = bytearray(camera.resolution[0] * camera.resolution[1] * 3)
|
|
||||||
|
|
||||||
#pygame-gui
|
|
||||||
gui_manager = pygame_gui.UIManager((screen.get_width(), screen.get_height()))
|
|
||||||
clock = pygame.time.Clock()
|
|
||||||
|
|
||||||
take_button = pygame_gui.elements.UIButton(relative_rect=pygame.Rect((720, 200), (80, 80)),
|
|
||||||
text='Take',
|
|
||||||
manager=gui_manager)
|
|
||||||
|
|
||||||
loop = True
|
|
||||||
while loop:
|
|
||||||
time_delta = clock.tick(60)/1000.0
|
|
||||||
for event in pygame.event.get():
|
|
||||||
if event.type == pygame.KEYDOWN:
|
|
||||||
if event.key == pygame.K_ESCAPE:
|
|
||||||
loop = False
|
|
||||||
elif event.type == pygame.QUIT:
|
|
||||||
loop = False
|
|
||||||
elif event.type == pygame.USEREVENT:
|
|
||||||
if event.user_type == pygame_gui.UI_BUTTON_PRESSED:
|
|
||||||
if event.ui_element == take_button:
|
|
||||||
take_picture(camera, cam_capture_resolution, './images')
|
|
||||||
# reset_resolution(camera, cam_viewfinder_resolution, cam_viewfinder_framerate)
|
|
||||||
set_cam_resolution(camera, cam_viewfinder_resolution, cam_viewfinder_framerate)
|
|
||||||
gui_manager.process_events(event)
|
|
||||||
|
|
||||||
gui_manager.update(time_delta)
|
|
||||||
|
|
||||||
stream = io.BytesIO()
|
|
||||||
camera.capture(stream, use_video_port=True, format='rgb')
|
|
||||||
stream.seek(0)
|
|
||||||
stream.readinto(rgb)
|
|
||||||
stream.close()
|
|
||||||
img = pygame.image.frombuffer(rgb[0:(camera.resolution[0] * camera.resolution[1] * 3)], camera.resolution, 'RGB')
|
|
||||||
img = pygame.transform.scale(img, (screen.get_width(), screen.get_height()))
|
|
||||||
|
|
||||||
if img:
|
|
||||||
screen.blit(img, (0, 0))
|
|
||||||
|
|
||||||
gui_manager.draw_ui(screen)
|
|
||||||
pygame.display.update()
|
|
||||||
|
|
||||||
camera.close()
|
|
||||||
pygame.display.quit()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
pygame==1.9.6
|
|
||||||
pygame-gui==0.5.7
|
|
||||||
20
src/CMakeLists.txt
Normal file
20
src/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
add_executable(
|
||||||
|
JAMCS
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(
|
||||||
|
JAMCS
|
||||||
|
PRIVATE
|
||||||
|
${GTK_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
target_link_directories(
|
||||||
|
JAMCS
|
||||||
|
PRIVATE
|
||||||
|
${GTK_LIBRARY_DIRS}
|
||||||
|
)
|
||||||
|
target_link_libraries(
|
||||||
|
JAMCS
|
||||||
|
PRIVATE
|
||||||
|
${GTK_LIBRARIES}
|
||||||
|
)
|
||||||
|
add_definitions (${GTK_CFLAGS_OTHER})
|
||||||
50
src/main.cpp
Normal file
50
src/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include <gtkmm.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class CloseButton : public Gtk::Button
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
void on_button_clicked();
|
||||||
|
Glib::RefPtr<Gtk::Application> app;
|
||||||
|
public:
|
||||||
|
CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app);
|
||||||
|
};
|
||||||
|
|
||||||
|
CloseButton::CloseButton(const Glib::ustring &label, Glib::RefPtr<Gtk::Application> app)
|
||||||
|
{
|
||||||
|
this->app = app;
|
||||||
|
|
||||||
|
set_label(label);
|
||||||
|
|
||||||
|
signal_clicked().connect(sigc::mem_fun(*this, &CloseButton::on_button_clicked));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseButton::on_button_clicked()
|
||||||
|
{
|
||||||
|
this->app.get()->quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyWindow : public Gtk::Window
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyWindow();
|
||||||
|
};
|
||||||
|
|
||||||
|
MyWindow::MyWindow()
|
||||||
|
{
|
||||||
|
set_title("Basic application");
|
||||||
|
set_default_size(200, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
auto app = Gtk::Application::create("org.gtkmm.examples.base");
|
||||||
|
MyWindow window;
|
||||||
|
|
||||||
|
CloseButton button("Close", app);
|
||||||
|
window.add(button);
|
||||||
|
window.show_all();
|
||||||
|
|
||||||
|
return app->run(window);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user