Fixing the camera 1

pull/1/head
Julius Riegel 7 years ago
parent 105bfdf1d7
commit a3afed06db

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="49388e57-2b9e-468a-b880-1d7fb243112d" name="Default" comment=""> <list default="true" id="49388e57-2b9e-468a-b880-1d7fb243112d" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/main.py" afterPath="$PROJECT_DIR$/main.py" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/graphiclib.py" afterPath="$PROJECT_DIR$/lib/graphiclib.py" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" /> <option name="TRACKING_ENABLED" value="true" />
@ -26,11 +26,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="main.py" pinned="false" current-in-tab="true"> <file leaf-file-name="main.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="304"> <state relative-caret-position="493">
<caret line="40" column="28" lean-forward="false" selection-start-line="40" selection-start-column="28" selection-end-line="40" selection-end-column="28" /> <caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" />
<folding> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>
@ -38,6 +38,18 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="graphiclib.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="474">
<caret line="85" column="24" lean-forward="false" selection-start-line="85" selection-start-column="24" selection-end-line="85" selection-end-column="24" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="update.sh" pinned="false" current-in-tab="false"> <file leaf-file-name="update.sh" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/update.sh"> <entry file="file://$PROJECT_DIR$/update.sh">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -87,6 +99,7 @@
<option value="$PROJECT_DIR$/thermo.py" /> <option value="$PROJECT_DIR$/thermo.py" />
<option value="$PROJECT_DIR$/update.sh" /> <option value="$PROJECT_DIR$/update.sh" />
<option value="$PROJECT_DIR$/main.py" /> <option value="$PROJECT_DIR$/main.py" />
<option value="$PROJECT_DIR$/lib/graphiclib.py" />
</list> </list>
</option> </option>
</component> </component>
@ -136,6 +149,11 @@
<item name="spydian" type="b2602c69:ProjectViewProjectNode" /> <item name="spydian" type="b2602c69:ProjectViewProjectNode" />
<item name="spydian" type="462c0819:PsiDirectoryNode" /> <item name="spydian" type="462c0819:PsiDirectoryNode" />
</path> </path>
<path>
<item name="spydian" type="b2602c69:ProjectViewProjectNode" />
<item name="spydian" type="462c0819:PsiDirectoryNode" />
<item name="lib" type="462c0819:PsiDirectoryNode" />
</path>
</expand> </expand>
<select /> <select />
</subPane> </subPane>
@ -282,12 +300,11 @@
</properties> </properties>
</breakpoint> </breakpoint>
</default-breakpoints> </default-breakpoints>
<option name="time" value="3" /> <option name="time" value="4" />
</breakpoint-manager> </breakpoint-manager>
<watches-manager /> <watches-manager />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/ultrasonic_test.py" />
<entry file="file://$PROJECT_DIR$/gyro.py" /> <entry file="file://$PROJECT_DIR$/gyro.py" />
<entry file="file://$PROJECT_DIR$/install.sh"> <entry file="file://$PROJECT_DIR$/install.sh">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -466,13 +483,23 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="304"> <state relative-caret-position="493">
<caret line="40" column="28" lean-forward="false" selection-start-line="40" selection-start-column="28" selection-end-line="40" selection-end-column="28" /> <caret line="41" column="28" lean-forward="true" selection-start-line="41" selection-start-column="28" selection-end-line="41" selection-end-column="28" />
<folding> <folding>
<element signature="e#0#19#0" expanded="true" /> <element signature="e#0#19#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/lib/graphiclib.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="474">
<caret line="85" column="24" lean-forward="false" selection-start-line="85" selection-start-column="24" selection-end-line="85" selection-end-column="24" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component> </component>
</project> </project>

@ -1,24 +1,26 @@
import pygame, pygame.camera import pygame, pygame.camera
import picamera
import picamera.array
from pygame import * from pygame import *
def render_text_line(image, color, font, text, pos = (0,0)):
def render_text_line(image, color, font, text, pos=(0, 0)):
render_text = font.render(text, 1, color) render_text = font.render(text, 1, color)
image.blit(render_text, pos) image.blit(render_text, pos)
class Screen: class Screen:
"""The Screen for the Terminal""" """The Screen for the Terminal"""
def __init__(self, size = (100,100), title = "Screen"): def __init__(self, size=(100, 100), title="Screen"):
pygame.display.init() pygame.display.init()
self.size = size self.size = size
self.screen = pygame.display.set_mode(self.size) self.screen = pygame.display.set_mode(self.size)
pygame.display.set_caption(title) pygame.display.set_caption(title)
def refresh(self, rectangles=None): def refresh(self, rectangles=None):
pygame.display.update(rectangles) pygame.display.update(rectangles)
def toggle_fullscreen(self): def toggle_fullscreen(self):
if self.fullscreen: if self.fullscreen:
pygame.display.set_mode(self.size) pygame.display.set_mode(self.size)
@ -38,15 +40,14 @@ class List(pygame.sprite.Sprite):
pygame.font.init() pygame.font.init()
self.size = size self.size = size
self.image = pygame.Surface(self.size) self.image = pygame.Surface(self.size)
self.image.fill((0,0,0)) self.image.fill((0, 0, 0))
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.rect.topleft = position self.rect.topleft = position
self.font = pygame.font.SysFont('Arial',25) self.font = pygame.font.SysFont('Arial', 25)
self.dict = {} self.dict = {}
self.updated = True self.updated = True
self.txtsize = self.font.size('__||__') self.txtsize = self.font.size('__||__')
def set_dict(self, dict): def set_dict(self, dict):
self.dict = dict self.dict = dict
self.updated = True self.updated = True
@ -57,10 +58,12 @@ class List(pygame.sprite.Sprite):
for key in self.dict.keys(): for key in self.dict.keys():
line = '{}: {}'.format(key, self.dict[key]) line = '{}: {}'.format(key, self.dict[key])
render_text_line(self.image, (255, 255, 255), self.font, line, (0,height)) render_text_line(self.image, (255, 255, 255), self.font, line, (0, height))
height+=self.txtsize[1] height += self.txtsize[1]
self.updated = False self.updated = False
print('update function called')
class PiCamera(pygame.sprite.Sprite): class PiCamera(pygame.sprite.Sprite):
"""The Picamera as pygame cam""" """The Picamera as pygame cam"""
@ -68,8 +71,7 @@ class PiCamera(pygame.sprite.Sprite):
def __init__(self, position, size): def __init__(self, position, size):
pygame.sprite.Sprite.__init__(self) pygame.sprite.Sprite.__init__(self)
pygame.camera.init() pygame.camera.init()
cam_list = pygame.camera.list_cameras() camera = picamera.PiCamera()
camera = pygame.camera.Camera(cam_list[0], size)
self.camera = camera self.camera = camera
self.size = size self.size = size
self.image = pygame.Surface(self.size) self.image = pygame.Surface(self.size)
@ -78,4 +80,7 @@ class PiCamera(pygame.sprite.Sprite):
self.rect.topleft = position self.rect.topleft = position
def update(self, *args): def update(self, *args):
self.camera.get_image(self.image) print('updating camera')
with picamera.array.PiRGBArray(self.camera, size=self.size) as output:
self.camera.capture(output, 'rgb', resize=self.size)
print(output)
Loading…
Cancel
Save