19 Commits
dev ... cpp

Author SHA1 Message Date
James
9d01729c4b fix 2022-03-04 18:21:28 +00:00
James
ac02297915 Artifact built file 2022-03-04 18:20:30 +00:00
James
f63948b295 Change compiler to clang 2022-03-04 18:14:52 +00:00
James
b3e4ba50a2 Update README 2022-03-04 18:07:08 +00:00
James H
374d29629b Add simple gtkmm3 code 2022-01-03 16:13:10 +00:00
James H
0871c54dda Update gitignore 2022-01-03 16:12:56 +00:00
James H
a5e5f0f90d #20 add clang-tidy linting to cmake 2022-01-03 15:12:18 +00:00
James H
0b3ca62c4c #20 add build-essential 2022-01-03 14:56:41 +00:00
James H
a8ec8bdeab Merge branch 'dev' of ssh://gitlab.hodgyj.com:22022/james/PiCamera into dev 2022-01-03 14:49:54 +00:00
James H
b4cb055995 Update to use gtkmm 3 2022-01-03 14:49:52 +00:00
James H
cacd94da62 Update .gitlab-ci.yml file to use debian image 2022-01-03 14:17:24 +00:00
James H
9b7daea177 Update .gitlab-ci.yml file 2022-01-03 14:15:05 +00:00
James H
0073d1f9c3 Add gtk example 2022-01-03 14:13:43 +00:00
James H
e750a4f523 Update .gitlab-ci.yml file 2022-01-03 14:13:23 +00:00
James H
130167b97d Update .gitlab-ci.yml file 2022-01-03 14:07:24 +00:00
James H
70198157fb #20 Add template .gitlab-ci.yml file 2022-01-03 12:58:23 +00:00
James H
0fcae4bdb1 Update README 2022-01-03 12:05:45 +00:00
James H
169fe5e234 Update gitignore to remove build folder 2022-01-03 12:05:36 +00:00
James H
1a0e25bf83 Remove python stuff to swap over to C++ 2022-01-03 11:20:14 +00:00
11 changed files with 198 additions and 294 deletions

160
.gitignore vendored
View File

@@ -1,133 +1,43 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Prerequisites
*.d
# C extensions
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# Fortran module files
*.mod
*.smod
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# 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/
# Executables
*.exe
*.out
*.app
# Images taken by the camera
images/
.vscode
# VSCode stuff
.vscode/
.devcontainer/
*.code-workspace
# Build folder
build/

57
.gitlab-ci.yml Normal file
View 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
View 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)

View File

@@ -1,13 +1,28 @@
# PiCamera
Camera for Raspberry Pi
# JAMCS - James Camera Software
Camera for Raspberry Pi in C++ :)
## How to run
Either:
## 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
```
chmod +x ./start.sh
./start.sh
### Fedora
```bash
sudo dnf install clang cmake gtkmm30-devel clang-tools-extra
```
Or:
```
python3 src/main.py
Then:
```bash
cmake -B build .
cmake --build build
```
Alternatively you can just use the VSCode CMake Extension

View File

@@ -1,2 +0,0 @@
pygame==1.9.6
pygame-gui==0.5.7

20
src/CMakeLists.txt Normal file
View 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
View 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);
}

View File

@@ -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()

View File

@@ -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()

View File

@@ -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())

View File

@@ -1 +0,0 @@
python3 src/main.py