Skip to content

Commit

Permalink
fix init camera parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
toinsson committed Aug 30, 2016
1 parent 0d29864 commit cd69f4e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
38 changes: 35 additions & 3 deletions src/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,39 @@
pyrs.start()
time.sleep(2)

cm = pyrs.get_colour()
plt.imshow(cm)
plt.show()
# cm = pyrs.get_colour()
# plt.imshow(cm)
# plt.show()

import cv2
import numpy as np
import time



cnt = 0
last = time.time()
smoothing = 0.9;
fps_smooth = 30

while True:

cnt += 1
if (cnt % 10) == 0:
now = time.time()
dt = now - last
fps = 10/dt
fps_smooth = (fps_smooth * smoothing) + (fps * (1.0-smoothing))
last = now

c = pyrs.get_colour()
d = pyrs.get_depth() >> 3
d = cv2.applyColorMap(d.astype(np.uint8), cv2.COLORMAP_RAINBOW)

cd = np.concatenate((c,d), axis=1)

cd = cv2.putText(cd, str(fps_smooth)[:4], (0,50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,0))

cv2.imshow('', cd)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
18 changes: 6 additions & 12 deletions src/realsense.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ void check_error()
rs_context * ctx = NULL;
rs_device * dev = NULL;

// global camera parameters
rs_intrinsics depth_intrin, color_intrin;
rs_extrinsics depth_to_color;


float scale;

// static Py

static PyObject *create_context(PyObject *self, PyObject *args, PyObject *keywds)
{
// parse arguments
Expand Down Expand Up @@ -608,9 +605,11 @@ static PyMethodDef RealSenseMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel */
};

void init_default_rs_extrinsics_value(void);
void init_default_rs_extrinsics_value(void)
void init_default_camera_parameters(void);
void init_default_camera_parameters(void)
{
scale = 0.00012498664727900177;

// save static values for calling projection functions when camera not present
depth_to_color.rotation[0] = 0.999998;
depth_to_color.rotation[1] = -0.001382;
Expand All @@ -625,11 +624,7 @@ void init_default_rs_extrinsics_value(void)
depth_to_color.translation[0] = 0.025700;
depth_to_color.translation[1] = -0.000733;
depth_to_color.translation[2] = 0.003885;
}

void init_default_rs_intrinsics_value(void);
void init_default_rs_intrinsics_value(void)
{
// save static values for calling projection functions when camera not present
color_intrin.width = 640;
color_intrin.height = 480;
Expand Down Expand Up @@ -664,8 +659,7 @@ PyMODINIT_FUNC initpyrealsense(void)
import_array();

// init default values
init_default_rs_intrinsics_value();
init_default_rs_extrinsics_value();
init_default_camera_parameters();
}


Expand Down

0 comments on commit cd69f4e

Please sign in to comment.