This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8549af8
commit 0a225cd
Showing
15 changed files
with
745 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,80 @@ | ||
|
||
class VideoCapture(): | ||
class MaixVideo(): | ||
|
||
def __init__(self, source="/dev/video", size=(640, 480)): | ||
self.source = source | ||
def __init__(self, size=(640, 480)): | ||
self.width, self.height = size | ||
|
||
def write(self): | ||
pass # for file | ||
|
||
def read(self): | ||
return b'\x00\xFF\x00' * (self.width * self.height) | ||
return b'\xFF\x00\x00' * (self.width * self.height) | ||
|
||
def capture(self): | ||
from PIL import Image | ||
return Image.frombytes("RGB", (self.width, self.height), self.read()) | ||
return Image.frombytes( | ||
"RGB", (self.width, self.height), self.read()) | ||
|
||
def close(self): | ||
pass # for file | ||
|
||
|
||
camera = VideoCapture() | ||
camera = MaixVideo() | ||
|
||
try: | ||
# use libmaix on v831 | ||
from libmaix import Camera | ||
|
||
class V831VideoCapture(VideoCapture): | ||
class V831MaixVideo(MaixVideo): | ||
|
||
def __init__(self, source="/sipeed/v831", size=(480, 360)): | ||
def __init__(self, source="/v831", size=(480, 360)): | ||
super(V831MaixVideo, self).__init__(size) | ||
self.source = source | ||
self.width, self.height = size | ||
self.cam = Camera(self.width, self.height) | ||
|
||
def read(self): | ||
return self.cam.read() # bytes | ||
return self.cam.read() | ||
|
||
def __del__(self): | ||
self.cam.close() | ||
|
||
camera = V831VideoCapture() | ||
camera = V831MaixVideo() | ||
except Exception as e: | ||
pass | ||
|
||
try: | ||
from cv2 import VideoCapture | ||
|
||
class CvMaixVideo(MaixVideo): | ||
|
||
def __init__(self, source=0, size=(640, 480)): | ||
super(CvMaixVideo, self).__init__(size) | ||
self.source = source | ||
self.cam = VideoCapture(0) | ||
|
||
def read(self): | ||
ret, frame = self.cam.read() | ||
if ret: | ||
bgr = frame[..., ::-1] # bgr2rgb | ||
return bgr.tobytes() # bytes | ||
return None | ||
|
||
def __del__(self): | ||
self.cam.release() | ||
|
||
camera = CvMaixVideo() | ||
except Exception as e: | ||
pass | ||
|
||
if __name__ == '__main__': | ||
''' | ||
def test_cv(): | ||
import cv2 | ||
cap = cv2.VideoCapture(0) | ||
print(cap) | ||
while True: | ||
ret, frame = cap.read() | ||
print(ret, type(frame)) | ||
if frame is not None: | ||
cv2.imshow("Video", frame) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
cap.release() | ||
cv2.destroyAllWindows() | ||
# test_cv() | ||
''' | ||
import display | ||
# display.clear((255, 0, 0)) | ||
display.clear((255, 0, 0)) | ||
display.show(camera.capture()) | ||
# tmp = camera.read() | ||
# import _maix | ||
# frame = _maix.rgb2jpg(camera.rgbbuf, camera.width, camera.height) | ||
# print(len(frame) // 1024, camera.width, camera.height) | ||
# from PIL import Image | ||
# from io import BytesIO | ||
# img = Image.open(BytesIO(frame)) | ||
# img.show() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .Video import camera | ||
from .import display | ||
from .import display, rpycs | ||
|
||
__all__ = ['display', 'Video', 'camera', 'rpycs'] | ||
|
||
__all__ = ['display', 'Video', 'camera'] |
Oops, something went wrong.