-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
103 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# %% | ||
import os | ||
os.environ['DISPLAY'] = ':0' | ||
|
||
# %% | ||
from pyk4a import PyK4A | ||
|
||
# Load camera with the default config | ||
k4a = PyK4A() | ||
k4a.start() | ||
|
||
# %% | ||
k4a.exposure_mode_auto = (True, 100) | ||
|
||
# %% | ||
k4a.exposure_mode_auto = False | ||
k4a.exposure = 8330 | ||
# k4a.brightness = 1000 | ||
|
||
# %% | ||
# Get the next capture (blocking function) | ||
capture = k4a.get_capture() | ||
img_color = capture.color | ||
|
||
# Display with pyplot | ||
from matplotlib import pyplot as plt | ||
plt.imshow(img_color[:, :, 2::-1]) # BGRA to RGB | ||
plt.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import argparse | ||
import pickle | ||
from io import BytesIO | ||
|
||
import imageio | ||
import numpy as np | ||
from aiohttp import web | ||
|
||
import pyk4a | ||
from pyk4a import Config, PyK4A | ||
|
||
# launch kinect | ||
k4a = PyK4A( | ||
Config( | ||
camera_fps=pyk4a.FPS.FPS_30, | ||
color_resolution=pyk4a.ColorResolution.RES_720P, | ||
depth_mode=pyk4a.DepthMode.NFOV_UNBINNED, | ||
) | ||
) | ||
k4a.start() | ||
|
||
# set exposure parameters | ||
k4a.exposure_mode_auto = False | ||
k4a.exposure = 8330 | ||
|
||
async def view_handle(request): | ||
img_buf = BytesIO() | ||
capture = k4a.get_capture() | ||
color_img = capture.color | ||
depth_img = capture.transformed_depth | ||
|
||
color_img = color_img[...,[2,1,0]].astype(np.float32) / 255.0 | ||
depth_img = depth_img.astype(np.float32) | ||
|
||
depth_img -= np.min(depth_img) | ||
depth_img /= np.max(depth_img) | ||
img = np.concatenate([color_img, np.repeat(depth_img[:, :, np.newaxis], 3, axis=2)], axis=0) | ||
imageio.imwrite(img_buf, (img * 255).astype(np.uint8), format='jpeg') | ||
|
||
return web.Response(body=img_buf.getbuffer(), content_type='image/jpeg') | ||
|
||
|
||
async def pickle_handle(request): | ||
img_buf = BytesIO() | ||
capture = k4a.get_capture() | ||
color_img = capture.color | ||
depth_img = capture.transformed_depth | ||
color_img = color_img[...,[2,1,0]] | ||
|
||
enc = pickle.dumps({ | ||
'color_img':color_img, | ||
'depth_img':depth_img | ||
}) | ||
return web.Response(body=enc) | ||
|
||
|
||
async def intr_handle(request): | ||
color_intr = k4a.calibration.get_camera_matrix(pyk4a.calibration.CalibrationType.COLOR) | ||
enc = pickle.dumps(color_intr) | ||
return web.Response(body=enc) | ||
|
||
|
||
app = web.Application() | ||
app.add_routes([web.get('/', view_handle), | ||
web.get('/view', view_handle), | ||
web.get('/intr', intr_handle), | ||
web.get('/pickle', pickle_handle)]) | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser("Kinect Server") | ||
parser.add_argument("--port", type=int, default=8080, help="port") | ||
args = parser.parse_args() | ||
|
||
web.run_app(app, port=args.port) |