Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e4ab292347 | |||
| 7e422dca80 | |||
| 80847c5439 | |||
| 2699edc3ac | |||
| f8291acdc5 |
@@ -1,8 +1,2 @@
|
|||||||
|
|
||||||
src/.DS_Store
|
src/.DS_Store
|
||||||
.DS_Store
|
|
||||||
Project.xcconfig
|
|
||||||
bin/
|
|
||||||
openFrameworks-Info.plist
|
|
||||||
opencvExample.xcodeproj/
|
|
||||||
config.refindx
|
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<!-- THIS FILE NEEDS TO GO IN THE APPLICATION /data/ folder -->
|
||||||
|
|
||||||
|
<config>
|
||||||
|
<mode>analysis</mode>
|
||||||
|
|
||||||
|
<camera>
|
||||||
|
<id>1</id>
|
||||||
|
<width>640</width>
|
||||||
|
<height>480</height>
|
||||||
|
</camera>
|
||||||
|
|
||||||
|
<display>
|
||||||
|
<fps>30</fps>
|
||||||
|
</display>
|
||||||
|
|
||||||
|
<locale>
|
||||||
|
<name>FUTURE</name>
|
||||||
|
</locale>
|
||||||
|
|
||||||
|
<analysis_NUM_RUN>
|
||||||
|
<NUM_RUN_shadowscapes> 1 </NUM_RUN_shadowscapes>
|
||||||
|
<NUM_RUN_relaxrate> 1 </NUM_RUN_relaxrate>
|
||||||
|
<NUM_RUN_iresponse> 1 </NUM_RUN_iresponse>
|
||||||
|
<NUM_RUN_shapefromshading> 1 </NUM_RUN_shapefromshading>
|
||||||
|
<NUM_RUN_strobe> 1 </NUM_RUN_strobe>
|
||||||
|
<NUM_RUN_camnoise> 1 </NUM_RUN_camnoise>
|
||||||
|
<NUM_RUN_colorsingle> 1 </NUM_RUN_colorsingle>
|
||||||
|
<NUM_RUN_colormulti> 1 </NUM_RUN_colormulti>
|
||||||
|
<NUM_RUN_diffnoise> 1 </NUM_RUN_diffnoise>
|
||||||
|
</analysis_NUM_RUN>
|
||||||
|
|
||||||
|
<analysis_time>
|
||||||
|
<acquiretime_shadowscapes> 7 </acquiretime_shadowscapes>
|
||||||
|
<acquiretime_relaxrate> 10 </acquiretime_relaxrate>
|
||||||
|
<acquiretime_iresponse> 30 </acquiretime_iresponse>
|
||||||
|
<acquiretime_shapefromshading> 30 </acquiretime_shapefromshading>
|
||||||
|
<acquiretime_strobe> 30 </acquiretime_strobe>
|
||||||
|
<acquiretime_camnoise> 30 </acquiretime_camnoise>
|
||||||
|
<acquiretime_colorsingle> 40 </acquiretime_colorsingle>
|
||||||
|
<acquiretime_colormulti> 15 </acquiretime_colormulti>
|
||||||
|
<acquiretime_diffnoise> 30 </acquiretime_diffnoise>
|
||||||
|
</analysis_time>
|
||||||
|
|
||||||
|
<algorithms>
|
||||||
|
<vertices_per_frame>1000</vertices_per_frame>
|
||||||
|
<pixel_per_vertex>4</pixel_per_vertex>
|
||||||
|
|
||||||
|
<colormulti>
|
||||||
|
<algo>2</algo>
|
||||||
|
<scale>2</scale>
|
||||||
|
<draw_style>3</draw_style>
|
||||||
|
<line_width>2</line_width>
|
||||||
|
</colormulti>
|
||||||
|
|
||||||
|
<relaxrate>
|
||||||
|
<algo>4</algo>
|
||||||
|
<scale>600</scale>
|
||||||
|
<draw_style>2</draw_style>
|
||||||
|
<line_width>4</line_width>
|
||||||
|
</relaxrate>
|
||||||
|
|
||||||
|
<shadowscapes>
|
||||||
|
<algo>1</algo>
|
||||||
|
<scale>650</scale>
|
||||||
|
<draw_style>1</draw_style>
|
||||||
|
<line_width>1</line_width>
|
||||||
|
</shadowscapes>
|
||||||
|
|
||||||
|
</algorithms>
|
||||||
|
|
||||||
|
<relaxrate>
|
||||||
|
<treshold>51</treshold>
|
||||||
|
<maxblobs>25</maxblobs>
|
||||||
|
</relaxrate>
|
||||||
|
|
||||||
|
</config>
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
/*
|
||||||
|
~ copyright (c) 2011 dviid
|
||||||
|
~ contact: dviid@labs.ciid.dk
|
||||||
|
|
||||||
|
+ redistribution and use in source and binary forms, with or without
|
||||||
|
+ modification, are permitted provided that the following conditions
|
||||||
|
+ are met:
|
||||||
|
+ > redistributions of source code must retain the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer.
|
||||||
|
+ > redistributions in binary form must reproduce the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer in
|
||||||
|
+ the documentation and/or other materials provided with the
|
||||||
|
+ distribution.
|
||||||
|
|
||||||
|
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
+ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
+ SUCH DAMAGE.
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
*/
|
||||||
|
|
||||||
|
const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
|
||||||
|
|
||||||
|
const sampler_t smp_adrs = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;
|
||||||
|
|
||||||
|
|
||||||
|
float box_integral(read_only image2d_t src, int width, int height, int row, int col, int nbrrows, int nbrcols)
|
||||||
|
{
|
||||||
|
float A = 0.0f;
|
||||||
|
float B = 0.0f;
|
||||||
|
float C = 0.0f;
|
||||||
|
float D = 0.0f;
|
||||||
|
|
||||||
|
int r0 = min(row, height) - 1;
|
||||||
|
int c0 = min(col, width) - 1;
|
||||||
|
int r1 = min(row + nbrrows, height) - 1;
|
||||||
|
int c1 = min(col + nbrcols, width) - 1;
|
||||||
|
|
||||||
|
A = read_imagef(src, smp, (int2)(c0, r0)).x;
|
||||||
|
B = read_imagef(src, smp, (int2)(c1, r0)).x;
|
||||||
|
C = read_imagef(src, smp, (int2)(c0, r1)).x;
|
||||||
|
D = read_imagef(src, smp, (int2)(c1, r1)).x;
|
||||||
|
|
||||||
|
return max(0.0f, A - B - C + D);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__kernel void hessian_det(
|
||||||
|
read_only image2d_t src,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
write_only image2d_t determinant,
|
||||||
|
write_only image2d_t laplacians,
|
||||||
|
int layer_width,
|
||||||
|
int layer_height,
|
||||||
|
int step,
|
||||||
|
int filter)
|
||||||
|
{
|
||||||
|
int l, w, b;
|
||||||
|
float Dxx, Dxy, Dyy, inverse;
|
||||||
|
|
||||||
|
int idx = get_global_id(0);
|
||||||
|
int idy = get_global_id(1);
|
||||||
|
|
||||||
|
w = filter;
|
||||||
|
l = w / 3;
|
||||||
|
b = (w - 1) / 2 + 1
|
||||||
|
inverse = 1.0f / (w * w);
|
||||||
|
|
||||||
|
int c = idx * step;
|
||||||
|
int r = idy * step;
|
||||||
|
|
||||||
|
if(r >= height || c >= width) return;
|
||||||
|
|
||||||
|
Dxx = box_integral(src, width, height, r - l + 1, c - b, 2 * l - 1, w) -
|
||||||
|
box_integral(src, width, height, r - l + 1, c - l / 2, 2 * l - 1, l) * 3;
|
||||||
|
|
||||||
|
Dxy = box_integral(src, width, height, r - l, c + 1, l, l) +
|
||||||
|
box_integral(src, width, height, r + 1, c - l, l, l) -
|
||||||
|
box_integral(src, width, height, r - 1, c - l, l, l) -
|
||||||
|
box_integral(src, widht, height, r + 1, c + 1, l, l);
|
||||||
|
|
||||||
|
DYY = box_integral(src, width, height, r - b, c - l + 1, w, 2 * l - 1) -
|
||||||
|
box_integral(src, width, height, r - l / 2, c - l + 1, l, 2 * l -1) * 3;
|
||||||
|
|
||||||
|
Dxx += inverse;
|
||||||
|
Dxy += inverse;
|
||||||
|
Dyy += inverse;
|
||||||
|
|
||||||
|
float4 det = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
|
det.x = (Dxx * Dyy - 0.81f * Dxy * Dxy);
|
||||||
|
|
||||||
|
int4 lap = {0, 0, 0, 0};
|
||||||
|
lap.x = (Dxx + Dyy >= 0 ? 1 : 0);
|
||||||
|
|
||||||
|
write_imagef(determinant, (int2)(idx, idy), det);
|
||||||
|
write_imagef(laplacians, (int2)(idx, idy), lap);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int pop_laplacian(read_only image2d_t layer, int c, int r, int width)
|
||||||
|
{
|
||||||
|
int lap;
|
||||||
|
lap = read_imagei(layer, smp_adrs, (int2)(c,r)).x;
|
||||||
|
return lap;
|
||||||
|
}
|
||||||
|
|
||||||
|
float pop_response(read_only image2d_t layer, int c, int r, int width, int scale)
|
||||||
|
{
|
||||||
|
float resp;
|
||||||
|
resp = read_imagef(layer, smp_adrs, (int2)(c*scale, r*scale)).x;
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool interpolate_extremum(
|
||||||
|
int r,
|
||||||
|
int c,
|
||||||
|
__global int* pts_cnt;
|
||||||
|
float2* pos,
|
||||||
|
float* det_scale
|
||||||
|
int* laplacian,
|
||||||
|
read_only image2d_t t,
|
||||||
|
int t_width,
|
||||||
|
int t_height,
|
||||||
|
int t_step,
|
||||||
|
read_only image2d_t m,
|
||||||
|
read_only image2d_t mlaplacian,
|
||||||
|
int m_width,
|
||||||
|
int m_height,
|
||||||
|
int m_filter,
|
||||||
|
read_only image2d_t b,
|
||||||
|
int b_width,
|
||||||
|
int b_height,
|
||||||
|
int b_filter
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 3D derivatives
|
||||||
|
|
||||||
|
int mscale = (m_width / m_height);
|
||||||
|
int bscale = (b_width / b_height);
|
||||||
|
|
||||||
|
float Dx, Dy, Dz;
|
||||||
|
|
||||||
|
Dx = (pop_response(m, c+1, r, m_width, mscale) -
|
||||||
|
pop_response(m, c-1, r, m_width, mscale)) / 2.0f;
|
||||||
|
Dy = (pop_response(m, c, r+1, m_width, mscale) -
|
||||||
|
pop_response(m, c, r-1, m_width, mscale)) / 2.0f;
|
||||||
|
|
||||||
|
Dz = (pop_response(t, c, r, t_width, 1) -
|
||||||
|
pop_response(b, c, r, b_width, bscale)) / 2.0f;
|
||||||
|
|
||||||
|
// inverse hessian
|
||||||
|
|
||||||
|
float v, Dxx, Dyy, Dzz, Dxy, Dxz, Dyz;
|
||||||
|
|
||||||
|
v = pop_response(m, r, c, m_width, mscale);
|
||||||
|
|
||||||
|
Dxx = pop_response(m, c+1, r, m_width, mscale) +
|
||||||
|
pop_response(m, c-1, r, m_width, mscale) - 2.0f * v;
|
||||||
|
|
||||||
|
Dyy = pop_response(m, c, r+1, m_width, mscale) +
|
||||||
|
pop_response(m, c, r-1, m_width, mscale) - 2.0f * v;
|
||||||
|
|
||||||
|
Dxy = (pop_response(m, c+1, r+1, m_width, mscale) -
|
||||||
|
pop_response(m, c-1, r+1, m_width, mscale) -
|
||||||
|
pop_response(m, c+1, r-1, m_width, mscale) +
|
||||||
|
pop_response(m, c-1, r-1, m_width, mscale)) / 4.0f;
|
||||||
|
|
||||||
|
Dzz = pop_response(t, c, r, t_width, 1) -
|
||||||
|
pop_response(b, c, r, b_width, bscale) - 2.0f * v;
|
||||||
|
|
||||||
|
Dxz = (pop_response(t, c+1, r, t_width, 1) -
|
||||||
|
pop_response(t, c-1, r, t_width, 1) -
|
||||||
|
pop_response(b, c+1, r, b_width, bscale) +
|
||||||
|
pop_response(b, c-1, r, b_width, bscale)) / 4.0f;
|
||||||
|
|
||||||
|
Dyz = (pop_response(t, c, r+1, t_width, 1) -
|
||||||
|
pop_response(t, c, r-1, t_width, 1) -
|
||||||
|
pop_response(b, c, r+1, b_width, bscale) +
|
||||||
|
pop_response(b, c, r-1, b_width, bscale)) / 4.0f;
|
||||||
|
|
||||||
|
float det = Dxx * (Dyy*Dzz - Dyz*Dyz) -
|
||||||
|
Dxy * (Dxy*Dzz - Dyz*Dxz) +
|
||||||
|
Dxz * (Dxy*Dyz - Dyy*Dxz);
|
||||||
|
|
||||||
|
float invdet = 1.0f / det;
|
||||||
|
|
||||||
|
float invDxx = (Dyy*Dzz-Dyz*Dyz) * invdet;
|
||||||
|
float invDxy = -(Dxy*Dzz-Dyz*Dxz) * invdet;
|
||||||
|
float invDxz = (Dxy*Dyz-Dyy*Dxz) * invdet;
|
||||||
|
float invDyx = -(Dxy*Dzz-Dxz*Dyz) * invdet;
|
||||||
|
float invDyy = (Dxx*Dzz-Dxz*Dxz) * invdet;
|
||||||
|
float invDyz = -(Dxx*Dyz-Dxy*Dxz) * invdet;
|
||||||
|
float invDzx = (Dxy*Dyz-Dxz*Dyy) * invdet;
|
||||||
|
float invDzy = -(Dxx*Dyz-Dxz*Dxy) * invdet;
|
||||||
|
float invDzz = (Dxx*Dyy-Dxy*Dxy) * invdet;
|
||||||
|
|
||||||
|
// derivative * hessian
|
||||||
|
|
||||||
|
float xi = 0.0f, xr = 0.0f, xc = 0.0f;
|
||||||
|
|
||||||
|
xc -= invDxx * Dx;
|
||||||
|
xc -= invDxy * Dy;
|
||||||
|
xc -= invDxz * Dz;
|
||||||
|
|
||||||
|
xr -= invDyx * Dx;
|
||||||
|
xr -= invDyy * Dy;
|
||||||
|
xr -= invDyz * Dz;
|
||||||
|
|
||||||
|
xc -= invDzx * Dx;
|
||||||
|
xc -= invDzy * Dy;
|
||||||
|
xc -= invDzz * Dz;
|
||||||
|
|
||||||
|
// extremum??
|
||||||
|
if(fabs(xi) < 0.5f && fabs(xr) < 0.5f && fabs(xc) < 0.5f) {
|
||||||
|
|
||||||
|
int fstep = m_filter - b_filter;
|
||||||
|
|
||||||
|
(*pos).x = (float)((c + xc) * fstep);
|
||||||
|
(*pos).y = (float)((c + xr) * fstep);
|
||||||
|
*det_scale = (float)(0.1333f) * (m_filter + (xi * fstep));
|
||||||
|
|
||||||
|
int s = m_width / t_width;
|
||||||
|
*laplacian = pop_laplacian(mlaplacian, c * s, r * s, m_width);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_extremum(
|
||||||
|
int r,
|
||||||
|
int c,
|
||||||
|
read_only image2d_t t,
|
||||||
|
int t_width,
|
||||||
|
int t_height,
|
||||||
|
int t_step,
|
||||||
|
int t_filter,
|
||||||
|
read_only image2d_t m,
|
||||||
|
int m_width,
|
||||||
|
int m_height,
|
||||||
|
read_only image2d_t b,
|
||||||
|
int b_width,
|
||||||
|
int b_height,
|
||||||
|
float tresh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int border = (t_filter + 1) / (2 * t_step);
|
||||||
|
|
||||||
|
if(r <= border || r >= t_height - border || c <= border || c >= t_width - border) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mscale = m_width / t_width;
|
||||||
|
|
||||||
|
float candidate = pop_response(m, c, r, m_width, mscale);
|
||||||
|
if(candidate < tresh) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If any response in 3x3x3 is greater candidate not maximum
|
||||||
|
float localMax = getResponse(t, c-1, r-1, t_width, 1);
|
||||||
|
localMax = fmax(localMax, getResponse(t, c, r-1, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c+1, r-1, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c-1, r, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c, r, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c+1, r, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c-1, r+1, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c, r+1, t_width, 1));
|
||||||
|
localMax = fmax(localMax, getResponse(t, c+1, r+1, t_width, 1));
|
||||||
|
|
||||||
|
int bScale = b_width/t_width;
|
||||||
|
|
||||||
|
localMax = fmax(localMax, getResponse(b, c-1, r-1, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c, r-1, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c+1, r-1, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c-1, r, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c, r, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c+1, r, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c-1, r+1, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c, r+1, b_width, bScale));
|
||||||
|
localMax = fmax(localMax, getResponse(b, c+1, r+1, b_width, bScale));
|
||||||
|
|
||||||
|
//int mScale = m_width/t_width;
|
||||||
|
|
||||||
|
localMax = fmax(localMax, getResponse(m, c-1, r-1, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c, r-1, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c+1, r-1, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c-1, r, m_width, mScale));
|
||||||
|
// This is the candidate pixel
|
||||||
|
localMax = fmax(localMax, getResponse(m, c+1, r, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c-1, r+1, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c, r+1, m_width, mScale));
|
||||||
|
localMax = fmax(localMax, getResponse(m, c+1, r+1, m_width, mScale));
|
||||||
|
|
||||||
|
// If localMax > candidate, candidate is not the local maxima
|
||||||
|
if(localMax > candidate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void suppress_non_max(
|
||||||
|
read_only image2d_t tResponse,
|
||||||
|
int t_width,
|
||||||
|
int t_height,
|
||||||
|
int t_filter,
|
||||||
|
int t_step,
|
||||||
|
read_only image2d_t mResponse,
|
||||||
|
read_only image2d_t mLaplacian,
|
||||||
|
int m_width,
|
||||||
|
int m_height,
|
||||||
|
int m_filter,
|
||||||
|
read_only image2d_t bResponse,
|
||||||
|
int b_width;
|
||||||
|
int b_height,
|
||||||
|
int b_filter,
|
||||||
|
__global int* pts_cnt,
|
||||||
|
__global float2* pix_pos,
|
||||||
|
__global float* scale,
|
||||||
|
__global int* laplacian,
|
||||||
|
int max_pts,
|
||||||
|
float tresh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int r = get_global_id(0);
|
||||||
|
int c = get_global_id(1);
|
||||||
|
|
||||||
|
float2 pixpos;
|
||||||
|
float s;
|
||||||
|
int lap;
|
||||||
|
|
||||||
|
|
||||||
|
if(is_extremum(r, c, tResponse, t_width, t_height, t_step, t_filter, mResponse, m_width, m_height, bResponse, b_width, b_height, tresh)) {
|
||||||
|
|
||||||
|
if(interpolate_extremum(r, c, pts_cnt, &pixpos, &s, &lap, tResponse, t_width, t_height, t_step, mResponse, mLaplacian, m_width, m_height, m_filter, bResponse, b_width, b_height, b_filter)) {
|
||||||
|
|
||||||
|
int indx = atom_add(&pts_cnt[0],1);
|
||||||
|
if(indx < max_pts) {
|
||||||
|
pix_pos[indx] = pix_pos;
|
||||||
|
scale[indx] = s;
|
||||||
|
laplacian[indx] = lap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
~ copyright (c) 2011 dviid
|
||||||
|
~ contact: dviid@labs.ciid.dk
|
||||||
|
|
||||||
|
+ redistribution and use in source and binary forms, with or without
|
||||||
|
+ modification, are permitted provided that the following conditions
|
||||||
|
+ are met:
|
||||||
|
+ > redistributions of source code must retain the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer.
|
||||||
|
+ > redistributions in binary form must reproduce the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer in
|
||||||
|
+ the documentation and/or other materials provided with the
|
||||||
|
+ distribution.
|
||||||
|
|
||||||
|
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
+ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
+ SUCH DAMAGE.
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
*/
|
||||||
|
|
||||||
|
const sampler_t smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
|
||||||
|
|
||||||
|
__kernel void sobel(read_only image2d_t src, write_only image2d_t dst)
|
||||||
|
{
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
int2 dx = (int2)(1,0);
|
||||||
|
int2 dy = (int2)(0,1);
|
||||||
|
float Gx, Gy, G, theta, p;
|
||||||
|
|
||||||
|
if(coords.x > get_image_width(dst) || coords.y > get_image_height(dst))
|
||||||
|
return;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords - dx + dy).s0;
|
||||||
|
Gx = p;
|
||||||
|
Gy = p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords + dy).s0;
|
||||||
|
Gy += 2 * p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords + dx + dy).s0;
|
||||||
|
Gx -= p;
|
||||||
|
Gy += p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords - dx).s0;
|
||||||
|
Gx += 2 * p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords + dx).s0;
|
||||||
|
Gx -= 2 * p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords - dx - dy).s0;
|
||||||
|
Gx += p;
|
||||||
|
Gy -= p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords - dy).s0;
|
||||||
|
Gy -= 2 * p;
|
||||||
|
|
||||||
|
p = read_imagef(src, smp, coords + dx - dy).s0;
|
||||||
|
Gx -= p;
|
||||||
|
Gy -= p;
|
||||||
|
|
||||||
|
G = sqrt(Gx * Gx + Gy * Gy);
|
||||||
|
theta = atan(Gx / Gy);
|
||||||
|
|
||||||
|
write_imagef(dst, coords, G);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void hgauss(read_only image2d_t src, write_only image2d_t dst,
|
||||||
|
global read_only float* weights, global float* offsets, const int nbr_weights)
|
||||||
|
{
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
float2 src_coords = (float2) (get_global_id(0), get_global_id(1));
|
||||||
|
float4 pix = (float4)(0,0,0,0);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < nbr_weights; i++) {
|
||||||
|
pix += read_imagef(src, smp, src_coords + (float2) (offsets[i], 0.0f)) * weights[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
write_imagef(dst, coords, clamp(pix, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void vgauss(read_only image2d_t src, write_only image2d_t dst,
|
||||||
|
global read_only float* weights, global float* offsets, const int nbr_weights)
|
||||||
|
{
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
float2 src_coords = (float2) (get_global_id(0), get_global_id(1));
|
||||||
|
float4 pix = (float4)(0,0,0,0);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < nbr_weights; i++) {
|
||||||
|
pix += read_imagef(src, smp, src_coords + (float2) (0.0f, offsets[i])) * weights[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
write_imagef(dst, coords, clamp(pix, 0.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__kernel void grey(read_only image2d_t src, write_only image2d_t dst)
|
||||||
|
{
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
float4 color = read_imagef(src, smp, coords);
|
||||||
|
float luminance = 0.3f * color.x + 0.59 * color.y + 0.11 * color.z;
|
||||||
|
color = (float4)(luminance, luminance, luminance, 1.0f);
|
||||||
|
write_imagef(dst, coords, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void brightness(read_only image2d_t src, write_only image2d_t dst)
|
||||||
|
{
|
||||||
|
float max = 0;
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
float4 color = read_imagef(src, smp, coords);
|
||||||
|
|
||||||
|
max = color.x;
|
||||||
|
if(color.y > max) { max = color.y; }
|
||||||
|
if(color.z > max) { max = color.z; }
|
||||||
|
|
||||||
|
write_imagef(dst, coords, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void lightness(read_only image2d_t src, write_only image2d_t dst)
|
||||||
|
{
|
||||||
|
float l = 0;
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
float4 color = read_imagef(src, smp, coords);
|
||||||
|
|
||||||
|
l = (color.x + color.y + color.z) / 3.0f;
|
||||||
|
|
||||||
|
write_imagef(dst, coords, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
__kernel void hist()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
~ copyright (c) 2011 dviid
|
||||||
|
~ contact: dviid@labs.ciid.dk
|
||||||
|
|
||||||
|
+ redistribution and use in source and binary forms, with or without
|
||||||
|
+ modification, are permitted provided that the following conditions
|
||||||
|
+ are met:
|
||||||
|
+ > redistributions of source code must retain the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer.
|
||||||
|
+ > redistributions in binary form must reproduce the above copyright
|
||||||
|
+ notice, this list of conditions and the following disclaimer in
|
||||||
|
+ the documentation and/or other materials provided with the
|
||||||
|
+ distribution.
|
||||||
|
|
||||||
|
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
+ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
+ AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
+ SUCH DAMAGE.
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WORK_G_SIZE 64
|
||||||
|
#define HALF_WORK_G_SIZE (WORK_G_SIZE / 2)
|
||||||
|
|
||||||
|
const sampler_t smp = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
|
||||||
|
|
||||||
|
__kernel void scan(read_only image2d_t src, write_only image2d_t dst, int rows, int cols)
|
||||||
|
{
|
||||||
|
__local float data0[WORK_G_SIZE + HALF_WORK_G_SIZE];
|
||||||
|
__local float data1[WORK_G_SIZE + HALF_WORK_G_SIZE];
|
||||||
|
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
int X = coords.x;
|
||||||
|
int Y = coords.x;
|
||||||
|
|
||||||
|
if(coords.x < HALF_WORK_G_SIZE) {
|
||||||
|
data0[coords.x] = 0.0f;
|
||||||
|
data1[coords.x] = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
X += HALF_WORK_G_SIZE;
|
||||||
|
float max_val = 0.0f;
|
||||||
|
|
||||||
|
int it = cols / WORK_G_SIZE;
|
||||||
|
if(cols % WORK_G_SIZE != 0) {
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < it; i++) {
|
||||||
|
|
||||||
|
int col_offset = i * WORK_G_SIZE + coords.x;
|
||||||
|
|
||||||
|
data0[X] = read_imagef(src, smp, (int2)(col_offset, Y)).x;
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 1
|
||||||
|
data1[X] = data0[X] + data0[X-1];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 2
|
||||||
|
data0[X] = data1[X] + data1[X-2];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 4
|
||||||
|
data1[X] = data0[X] + data0[X-4];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 8
|
||||||
|
data0[X] = data1[X] + data1[X-8];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 16
|
||||||
|
data1[X] = data0[X] + data0[X-16];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
// 32
|
||||||
|
data0[X] = data1[X] + data1[X-32];
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
if(col_offset < cols) {
|
||||||
|
write_imagef(dst, (int2)(col_offset, Y), (float4)(data0[X] + max_val, 0.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
max_val += data0[WORK_G_SIZE + HALF_WORK_G_SIZE - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void transpose(read_only image2d_t src, write_only image2d_t dst, int rows, int cols)
|
||||||
|
{
|
||||||
|
|
||||||
|
__local float buff[256];
|
||||||
|
|
||||||
|
int2 coords = (int2) (get_global_id(0), get_global_id(1));
|
||||||
|
|
||||||
|
int inX = coords.x;
|
||||||
|
int inY = coords.y;
|
||||||
|
|
||||||
|
int lX = coords.x;
|
||||||
|
int lY = coords.y;
|
||||||
|
|
||||||
|
int ginX = coords.x * 16 + lX;
|
||||||
|
int ginY = coords.y * 16 + lY;
|
||||||
|
|
||||||
|
buff[lY * 16 + lX] = read_imagef(src, smp, (int2)(ginX, ginY)).x;
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
int outRows = rows;
|
||||||
|
int outCols = cols;
|
||||||
|
|
||||||
|
int outX = inX;
|
||||||
|
int outY = inY;
|
||||||
|
|
||||||
|
int goutX = coords.x * 16 + lX;
|
||||||
|
int goutY = coords.y * 16 + lY;
|
||||||
|
|
||||||
|
if(goutX >= 0 && goutX < outCols && goutY >=0 && goutY < outRows) {
|
||||||
|
write_imagef(dst, (int2)(goutX, goutY), (float4)(buff[lX * 16 + lY], 0.0f, 0.0f, 0.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
uniform int algo;
|
||||||
|
uniform sampler2DRect tex0;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
|
||||||
|
if(algo == 4) {
|
||||||
|
vec4 color = texture2DRect(tex0, gl_TexCoord[0].st);
|
||||||
|
float luminance = 0.3f * color.x + 0.59 * color.y + 0.11 * color.z;
|
||||||
|
//gl_FragColor = vec4(luminance, luminance, luminance, 1.0f);
|
||||||
|
gl_FragColor = vec4(1.0f, 1.0f, 1.0f, 0.5f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_FragColor = texture2DRect(tex0, gl_TexCoord[0].st);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
#version 120
|
||||||
|
#extension GL_EXT_geometry_shader4 : enable
|
||||||
|
|
||||||
|
#define ALGO_1 1
|
||||||
|
#define ALGO_2 2
|
||||||
|
#define ALGO_3 3
|
||||||
|
#define ALGO_4 4
|
||||||
|
|
||||||
|
uniform int algo;
|
||||||
|
uniform float scale;
|
||||||
|
uniform sampler2DRect tex0;
|
||||||
|
|
||||||
|
float max_color(vec3 rgb)
|
||||||
|
{
|
||||||
|
float max = rgb.r;
|
||||||
|
if(rgb.g > max) { max = rgb.g; }
|
||||||
|
if(rgb.b > max) { max = rgb.b; }
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
float min_color(vec3 rgb)
|
||||||
|
{
|
||||||
|
float min = rgb.r;
|
||||||
|
if(rgb.g < min) { min = rgb.g; }
|
||||||
|
if(rgb.b < min) { min = rgb.b; }
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hue(in vec4 color, out float h)
|
||||||
|
{
|
||||||
|
float max = max_color(color.rgb);
|
||||||
|
float min = min_color(color.rgb);
|
||||||
|
if(max == min) { h = 0.f; }
|
||||||
|
|
||||||
|
float hueSixth;
|
||||||
|
if(color.r == max) {
|
||||||
|
hueSixth = (color.g - color.b) / (max - min);
|
||||||
|
if(hueSixth < 0.f)
|
||||||
|
hueSixth += 6.f;
|
||||||
|
} else if (color.g == max) {
|
||||||
|
hueSixth = 2.f + (color.b - color.r) / (max - min);
|
||||||
|
} else {
|
||||||
|
hueSixth = 4.f + (color.r - color.g) / (max - min);
|
||||||
|
}
|
||||||
|
|
||||||
|
h = 255.f * hueSixth / 6.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saturation(in vec4 color, out float s)
|
||||||
|
{
|
||||||
|
float max = max_color(color.rgb);
|
||||||
|
float min = min_color(color.rgb);
|
||||||
|
if(max == min) { s = 0.f; }
|
||||||
|
|
||||||
|
s = 255.f * (max - min) / max;
|
||||||
|
}
|
||||||
|
|
||||||
|
void brightness(in vec4 color, out float b)
|
||||||
|
{
|
||||||
|
b = max_color(color.rgb);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toHSB(in vec3 rgb, out vec3 hsb)
|
||||||
|
{
|
||||||
|
float max = max_color(rgb);
|
||||||
|
float min = min_color(rgb);
|
||||||
|
|
||||||
|
if(max == min) {
|
||||||
|
hsb.x = 0.f;
|
||||||
|
hsb.y = 0.f;
|
||||||
|
hsb.z = 255.f * max;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float hueSixth;
|
||||||
|
if(rgb.r == max) {
|
||||||
|
hueSixth = (rgb.g - rgb.b) / (max - min);
|
||||||
|
if(hueSixth < 0.f)
|
||||||
|
hueSixth += 6.f;
|
||||||
|
} else if (rgb.g == max) {
|
||||||
|
hueSixth = 2.f + (rgb.b - rgb.r) / (max - min);
|
||||||
|
} else {
|
||||||
|
hueSixth = 4.f + (rgb.r - rgb.g) / (max - min);
|
||||||
|
}
|
||||||
|
hsb.x = 255.f * hueSixth / 6.f;
|
||||||
|
hsb.y = 255.f * (max - min) / max;
|
||||||
|
hsb.z = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(algo == ALGO_4 && mod(gl_PositionIn[0].y, 2.f) != 0) return;
|
||||||
|
|
||||||
|
for (int i = 0; i < gl_VerticesIn; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
gl_Position = gl_PositionIn[i];
|
||||||
|
|
||||||
|
vec4 color0 = texture2DRect(tex0, gl_TexCoordIn[i][0].st);
|
||||||
|
|
||||||
|
float depth = 0.f;
|
||||||
|
|
||||||
|
if(algo == ALGO_1) {
|
||||||
|
brightness(color0, depth);
|
||||||
|
}
|
||||||
|
else if(algo == ALGO_2) {
|
||||||
|
hue(color0, depth);
|
||||||
|
}
|
||||||
|
else if(algo == ALGO_3) {
|
||||||
|
saturation(color0, depth);
|
||||||
|
}
|
||||||
|
else if(algo == ALGO_4) {
|
||||||
|
brightness(color0, depth);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
brightness(color0, depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Position.x, gl_Position.y, depth * scale, 1.0);
|
||||||
|
gl_TexCoord[0] = gl_TexCoordIn[i][0];
|
||||||
|
|
||||||
|
EmitVertex();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
gl_FrontColor = gl_Color;
|
||||||
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
gl_Position = gl_Vertex;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+98
-138
@@ -15,11 +15,16 @@
|
|||||||
|
|
||||||
#include "ofxXmlSettings.h"
|
#include "ofxXmlSettings.h"
|
||||||
|
|
||||||
|
#include "ofxArcBall.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define CAMERA_ID 0
|
#define CAMERA_ID 0
|
||||||
#define CAMERA_ACQU_WIDTH 640
|
#define CAMERA_ACQU_WIDTH 640
|
||||||
#define CAMERA_ACQU_HEIGHT 480
|
#define CAMERA_ACQU_HEIGHT 480
|
||||||
|
|
||||||
#define LOCATION "MANCHESTER"
|
#define LOCATION "MIDDLESBOROUGH"
|
||||||
|
|
||||||
#define ISTATE_UNDEF 0xEEEE
|
#define ISTATE_UNDEF 0xEEEE
|
||||||
#define ISTATE_START 0xAAAA
|
#define ISTATE_START 0xAAAA
|
||||||
@@ -27,6 +32,22 @@
|
|||||||
#define ISTATE_TRANSITION 0xCCCC
|
#define ISTATE_TRANSITION 0xCCCC
|
||||||
#define ISTATE_END 0xDDDD
|
#define ISTATE_END 0xDDDD
|
||||||
|
|
||||||
|
static const int subdiv_pixels = 4;
|
||||||
|
|
||||||
|
static const int VID_W = 640, VID_H = 480;
|
||||||
|
static const int VERTICES_X = VID_W / subdiv_pixels, VERTICES_Y = VID_W / subdiv_pixels;
|
||||||
|
static const int TRI_W = 1000;
|
||||||
|
|
||||||
|
int draw_style = FACE;
|
||||||
|
|
||||||
|
#define ALGO_1 1
|
||||||
|
#define ALGO_2 2
|
||||||
|
#define ALGO_3 3
|
||||||
|
#define ALGO_4 4
|
||||||
|
|
||||||
|
int algo = ALGO_2;
|
||||||
|
float scale = 1.f;
|
||||||
|
|
||||||
|
|
||||||
int _state = ISTATE_UNDEF;
|
int _state = ISTATE_UNDEF;
|
||||||
|
|
||||||
@@ -40,12 +61,64 @@ string RefractiveIndex::_location;
|
|||||||
|
|
||||||
ofxXmlSettings RefractiveIndex::XML;
|
ofxXmlSettings RefractiveIndex::XML;
|
||||||
|
|
||||||
|
ofShader RefractiveIndex::_shader;
|
||||||
|
ofVboMesh RefractiveIndex::_mesh_vbo;
|
||||||
|
|
||||||
|
//ofxArcBall RefractiveIndex::cam;
|
||||||
|
|
||||||
|
string msg;
|
||||||
|
|
||||||
|
void RefractiveIndex::setup_shader_vbo()
|
||||||
|
{
|
||||||
|
|
||||||
|
int vertices_per_frame = XML.getValue("config:algorithms:vertices_per_frame", TRI_W);
|
||||||
|
int pixel_per_vertex = XML.getValue("config:algorithms:pixel_per_vertex", subdiv_pixels);
|
||||||
|
|
||||||
|
int vertices_X = _vid_w / pixel_per_vertex, vertices_Y = _vid_h / pixel_per_vertex;
|
||||||
|
|
||||||
|
// VBO
|
||||||
|
for(int i = 0; i < vertices_X; i++){
|
||||||
|
for(int j = 0; j < vertices_Y; j++) {
|
||||||
|
_verts.push_back(ofVec3f((i / (float)vertices_X) * vertices_per_frame, (j / (float) vertices_Y) * vertices_per_frame, 0.0f));
|
||||||
|
_tex.push_back(ofVec2f(i / (float)vertices_X * _vid_w, j / (float) vertices_Y * _vid_h));
|
||||||
|
if( ( i + 1 < vertices_X ) && ( j + 1 < vertices_Y ) ) {
|
||||||
|
//triangle #1
|
||||||
|
_ind.push_back( (i+0) * vertices_Y + (j+0) );
|
||||||
|
_ind.push_back( (i+1) * vertices_Y + (j+0) );
|
||||||
|
_ind.push_back( (i+1) * vertices_Y + (j+1) );
|
||||||
|
|
||||||
|
//triangle #2
|
||||||
|
_ind.push_back( (i+1) * vertices_Y + (j+1) );
|
||||||
|
_ind.push_back( (i+0) * vertices_Y + (j+1) );
|
||||||
|
_ind.push_back( (i+0) * vertices_Y + (j+0) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//ofEnableNormalizedTexCoords();
|
||||||
|
|
||||||
|
_mesh_vbo.addVertices(_verts);
|
||||||
|
_mesh_vbo.addTexCoords(_tex);
|
||||||
|
_mesh_vbo.addIndices(_ind);
|
||||||
|
|
||||||
|
_mesh_vbo.setMode(OF_PRIMITIVE_TRIANGLES);
|
||||||
|
|
||||||
|
// geometry shader
|
||||||
|
|
||||||
|
_shader.setGeometryInputType(GL_TRIANGLES);
|
||||||
|
_shader.setGeometryOutputType(GL_TRIANGLES);
|
||||||
|
_shader.setGeometryOutputCount(3);
|
||||||
|
_shader.load("dviid/rfi.vert.glsl", "dviid/rfi.frag.glsl", "dviid/rfi.geom.glsl");
|
||||||
|
printf("Maximum number of output vertices support is: %i\n", _shader.getGeometryMaxOutputCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RefractiveIndex::setup()
|
void RefractiveIndex::setup()
|
||||||
{
|
{
|
||||||
camDist=1000;
|
ofSetLogLevel(OF_LOG_VERBOSE);
|
||||||
|
|
||||||
|
ofHideCursor();
|
||||||
|
|
||||||
ofBackground(0, 0, 0);
|
|
||||||
ofSetBackgroundAuto(false);
|
|
||||||
bool save_config = false;
|
bool save_config = false;
|
||||||
|
|
||||||
cout << "Loading configuration..." << endl;
|
cout << "Loading configuration..." << endl;
|
||||||
@@ -101,45 +174,38 @@ void RefractiveIndex::setup()
|
|||||||
|
|
||||||
_analysisAdapator = NULL;
|
_analysisAdapator = NULL;
|
||||||
|
|
||||||
//getting a warning from the OFlog that the pixels aren't allocated
|
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR_ALPHA);
|
||||||
//void ofPixels::allocate(int w, int h, ofImageType type)
|
|
||||||
_pixels.allocate(_vid_w, _vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
setup_shader_vbo();
|
||||||
|
|
||||||
|
|
||||||
//TODO: whichever one of these is first - it always runs twice ?
|
//TODO: whichever one of these is first - it always runs twice ?
|
||||||
|
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(V)); //1
|
_analysisVector.push_back(new ShadowScapesAnalysis(V)); //1
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(H)); //2
|
_analysisVector.push_back(new ShadowScapesAnalysis(H)); //2
|
||||||
_analysisVector.push_back(new ShadowScapesAnalysis(D)); //3
|
_analysisVector.push_back(new ShadowScapesAnalysis(D)); //3
|
||||||
|
_analysisVector.push_back(new RelaxRateAnalysis()); //4
|
||||||
_analysisVector.push_back(new RelaxRateAnalysis()); //4
|
_analysisVector.push_back(new IResponseAnalysis()); //5
|
||||||
|
_analysisVector.push_back(new ShapeFromShadingAnalysis()); //6
|
||||||
_analysisVector.push_back(new IResponseAnalysis()); //5
|
_analysisVector.push_back(new StrobeAnalysis()); //7
|
||||||
|
_analysisVector.push_back(new CamNoiseAnalysis()); //8
|
||||||
_analysisVector.push_back(new ShapeFromShadingAnalysis()); //6
|
_analysisVector.push_back(new ColorSingleAnalysis()); //9
|
||||||
|
_analysisVector.push_back(new ColorMultiAnalysis()); //10
|
||||||
_analysisVector.push_back(new StrobeAnalysis()); //7
|
_analysisVector.push_back(new DiffNoiseAnalysis()); //11
|
||||||
|
|
||||||
_analysisVector.push_back(new CamNoiseAnalysis()); //8
|
|
||||||
|
|
||||||
_analysisVector.push_back(new ColorSingleAnalysis()); //9
|
|
||||||
|
|
||||||
_analysisVector.push_back(new ColorMultiAnalysis()); //0
|
|
||||||
|
|
||||||
_analysisVector.push_back(new DiffNoiseAnalysis()); //Q
|
|
||||||
|
|
||||||
//_currentAnalysisIndx = 0;
|
|
||||||
//_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
|
||||||
//_state = ISTATE_START;
|
|
||||||
|
|
||||||
_currentAnalysis = NULL;
|
_currentAnalysis = NULL;
|
||||||
_state = ISTATE_UNDEF;
|
_state = ISTATE_UNDEF;
|
||||||
|
|
||||||
|
// disbale <ESC> ?
|
||||||
|
//ofSetEscapeQuitsApp(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::analysis_cb(string & analysis)
|
void RefractiveIndex::analysis_cb(string & analysis)
|
||||||
{
|
{
|
||||||
assert(analysis == _currentAnalysis->_name);
|
assert(analysis == _currentAnalysis->_name);
|
||||||
|
|
||||||
_state = ISTATE_STOP;
|
_state = ISTATE_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,17 +215,6 @@ void RefractiveIndex::start_analysis()
|
|||||||
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
|
_analysisAdapator = new AnalysisAdaptor(_currentAnalysis);
|
||||||
_currentAnalysis->setup(_vid_w, _vid_h);
|
_currentAnalysis->setup(_vid_w, _vid_h);
|
||||||
_analysisAdapator->start();
|
_analysisAdapator->start();
|
||||||
|
|
||||||
//allocate fbo for HD
|
|
||||||
fbo.allocate(1920,1080);
|
|
||||||
|
|
||||||
// fbo.allocate( _currentAnalysis->_mesh_size_multiplier *_vid_w,_currentAnalysis->_mesh_size_multiplier * _vid_h);
|
|
||||||
//camera.setPosition((fbo.getWidth()/2), fbo.getHeight()/2,_currentAnalysis->_mesh_size_multiplier *500);
|
|
||||||
camera.setPosition(0, (fbo.getHeight()/2)+150, _currentAnalysis->_mesh_size_multiplier*500);
|
|
||||||
camera.setFov(65.0);
|
|
||||||
camera.setOrientation(ofVec3f(-2,0,0));
|
|
||||||
_meshRotation=0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::stop_analysis()
|
void RefractiveIndex::stop_analysis()
|
||||||
@@ -185,7 +240,6 @@ void RefractiveIndex::state_analysis()
|
|||||||
_currentAnalysisIndx = 0;
|
_currentAnalysisIndx = 0;
|
||||||
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
||||||
_state = ISTATE_START;
|
_state = ISTATE_START;
|
||||||
//_state = ISTATE_END;
|
|
||||||
} else {
|
} else {
|
||||||
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
_currentAnalysis = _analysisVector.at(_currentAnalysisIndx++);
|
||||||
_state = ISTATE_START;
|
_state = ISTATE_START;
|
||||||
@@ -217,58 +271,11 @@ void RefractiveIndex::update()
|
|||||||
|
|
||||||
void RefractiveIndex::draw()
|
void RefractiveIndex::draw()
|
||||||
{
|
{
|
||||||
// refractive mauve - this doesn't work... looks weird in various places.
|
|
||||||
//ofBackground(113, 110, 136);
|
|
||||||
|
|
||||||
// black
|
// black
|
||||||
ofBackground(0, 0, 0);
|
ofBackground(0, 0, 0);
|
||||||
|
|
||||||
if(_currentAnalysis){
|
if(_currentAnalysis)
|
||||||
|
|
||||||
_currentAnalysis->draw();
|
_currentAnalysis->draw();
|
||||||
|
|
||||||
if(_currentAnalysis->meshIsComplete){
|
|
||||||
|
|
||||||
fbo.begin();
|
|
||||||
ofClear(0,0,0);
|
|
||||||
|
|
||||||
glShadeModel(GL_SMOOTH);
|
|
||||||
|
|
||||||
|
|
||||||
camera.begin();
|
|
||||||
|
|
||||||
//this is a hack, I don't know how to colour the fbo with black pixels so I'm drawing a massive black rectangle in the background
|
|
||||||
/*
|
|
||||||
ofPushMatrix();
|
|
||||||
ofTranslate(0, 0,-500);
|
|
||||||
ofSetColor(0, 0, 0);
|
|
||||||
ofRect(-fbo.getWidth(), -fbo.getHeight(), fbo.getWidth()*3, fbo.getHeight()*3);
|
|
||||||
ofPopMatrix();
|
|
||||||
ofSetColor(255);
|
|
||||||
*/
|
|
||||||
//float xDiff= (fbo.getWidth()- 1.55*(_currentAnalysis->_mesh_size_multiplier * _vid_w))/2;
|
|
||||||
float xDiff= (fbo.getWidth()- 1.33333*(_currentAnalysis->_mesh_size_multiplier * _vid_w))/2;
|
|
||||||
float yDiff= (fbo.getHeight()-(_currentAnalysis->_mesh_size_multiplier * _vid_h))/2;
|
|
||||||
|
|
||||||
ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage );
|
|
||||||
//ofScale(1.33333,1.0,1.0);
|
|
||||||
//_currentAnalysis->aMesh.drawVertices(); // TODO: tom - why do you have the vertices drawing here?
|
|
||||||
_currentAnalysis->aMesh.drawFaces();
|
|
||||||
_currentAnalysis->aMesh.draw();
|
|
||||||
|
|
||||||
camera.end();
|
|
||||||
fbo.end();
|
|
||||||
|
|
||||||
ofPixels pixels;
|
|
||||||
fbo.readToPixels(pixels);
|
|
||||||
|
|
||||||
ofSaveImage(pixels,_currentAnalysis->meshFileName, OF_IMAGE_QUALITY_BEST);
|
|
||||||
//saving jpgs doesn't work - pngs only!
|
|
||||||
// PNG is fine - better for Final Cut anyway!
|
|
||||||
|
|
||||||
ofDisableBlendMode() ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::setup_camera()
|
void RefractiveIndex::setup_camera()
|
||||||
@@ -302,15 +309,10 @@ void RefractiveIndex::stop_camera()
|
|||||||
|
|
||||||
void RefractiveIndex::keyPressed (int key)
|
void RefractiveIndex::keyPressed (int key)
|
||||||
{
|
{
|
||||||
|
|
||||||
if( key =='f')
|
if( key =='f')
|
||||||
ofToggleFullscreen();
|
ofToggleFullscreen();
|
||||||
|
|
||||||
/* TODO: complete the below... would be good to trigger the Analysis from keypresses if needed... */
|
|
||||||
// currently this doesn't work... the save_cb's in the individual
|
|
||||||
// tried to add a stop_analysis(); call but it blocks the whole programme
|
|
||||||
|
|
||||||
// i.e.: ask david how to shut off the prior Analysis if it's not finished running from here?
|
|
||||||
|
|
||||||
if(key == 'x')
|
if(key == 'x')
|
||||||
{
|
{
|
||||||
if(_currentAnalysis)
|
if(_currentAnalysis)
|
||||||
@@ -418,48 +420,6 @@ void RefractiveIndex::keyPressed (int key)
|
|||||||
_state = ISTATE_TRANSITION;
|
_state = ISTATE_TRANSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TO DO: add a file dialog so we can save images to another hard drive...
|
|
||||||
e.g.: http://dev.openframeworks.cc/pipermail/of-dev-openframeworks.cc/2011-April/003125.html
|
|
||||||
|
|
||||||
>> case 's':
|
|
||||||
>> doSave ^= true;
|
|
||||||
>> doLoad = false;
|
|
||||||
>> if(doSave) {
|
|
||||||
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to save to", true);
|
|
||||||
>> if(r.bSuccess) {
|
|
||||||
>> saveCounter = 0;
|
|
||||||
>> savePath = r.getPath();
|
|
||||||
>> ofDirectory::createDirectory(savePath + "/color/");
|
|
||||||
>> ofDirectory::createDirectory(savePath + "/depth/");
|
|
||||||
>> printf("SAVE %s %s\n", r.getPath().c_str(), r.getName().c_str());
|
|
||||||
>> } else {
|
|
||||||
>> doSave = false;
|
|
||||||
>> }
|
|
||||||
>>
|
|
||||||
>> }
|
|
||||||
>> break;
|
|
||||||
>>
|
|
||||||
>> case 'l':
|
|
||||||
>> doLoad ^= true;
|
|
||||||
>> doSave = false;
|
|
||||||
>> if(doLoad) {
|
|
||||||
>> ofFileDialogResult r = ofSystemLoadDialog("Select path to load from", true);
|
|
||||||
>> if(r.bSuccess) {
|
|
||||||
>> loadCounter = 0;
|
|
||||||
>> loadPath = r.getPath();
|
|
||||||
>> ofDirectory dir;
|
|
||||||
>> loadMaxFiles = MAX(dir.listDir(loadPath + "/color"), dir.listDir(loadPath + "/depth"));
|
|
||||||
>> printf("LOAD %i %s %s\n", loadMaxFiles, r.getPath().c_str(), r.getName().c_str());
|
|
||||||
>> } else {
|
|
||||||
>> doLoad = false;
|
|
||||||
>> }
|
|
||||||
>>
|
|
||||||
>> }
|
|
||||||
>> break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefractiveIndex::exit()
|
void RefractiveIndex::exit()
|
||||||
|
|||||||
@@ -10,12 +10,16 @@
|
|||||||
|
|
||||||
#include "ofxOpenCv.h"
|
#include "ofxOpenCv.h"
|
||||||
#include "ofxXmlSettings.h"
|
#include "ofxXmlSettings.h"
|
||||||
#include "ofxOpenCv.h"
|
|
||||||
|
|
||||||
|
#include "ofxArcBall.h"
|
||||||
|
|
||||||
#define MODE_DRAWING 0xEEFF
|
#define MODE_DRAWING 0xEEFF
|
||||||
#define MODE_ANALYSING 0xFFEE
|
#define MODE_ANALYSING 0xFFEE
|
||||||
|
|
||||||
|
#define VERTS 1
|
||||||
|
#define WIRE 2
|
||||||
|
#define FACE 3
|
||||||
|
|
||||||
class RefractiveIndex : public ofBaseApp
|
class RefractiveIndex : public ofBaseApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -34,6 +38,8 @@ public:
|
|||||||
void stop_analysis();
|
void stop_analysis();
|
||||||
void state_analysis();
|
void state_analysis();
|
||||||
|
|
||||||
|
void setup_shader_vbo();
|
||||||
|
|
||||||
// ofx
|
// ofx
|
||||||
void keyPressed (int key);
|
void keyPressed (int key);
|
||||||
void keyReleased(int key){;}
|
void keyReleased(int key){;}
|
||||||
@@ -56,9 +62,6 @@ protected:
|
|||||||
AnalysisAdaptor* _analysisAdapator;
|
AnalysisAdaptor* _analysisAdapator;
|
||||||
vector<AbstractAnalysis*> _analysisVector;
|
vector<AbstractAnalysis*> _analysisVector;
|
||||||
|
|
||||||
float _meshRotation;
|
|
||||||
float camDist;
|
|
||||||
ofEasyCam cam;
|
|
||||||
public:
|
public:
|
||||||
// acquisition
|
// acquisition
|
||||||
static ofPixels _pixels;
|
static ofPixels _pixels;
|
||||||
@@ -73,8 +76,17 @@ public:
|
|||||||
// this should be in xml
|
// this should be in xml
|
||||||
static string _location;
|
static string _location;
|
||||||
static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses
|
static ofxXmlSettings XML; // made this static so we can access RUN_NUM in the analyses
|
||||||
ofCamera camera;
|
|
||||||
ofPixels keepOnScreen;
|
|
||||||
ofFbo fbo;
|
static ofVboMesh _mesh_vbo;
|
||||||
|
|
||||||
|
vector<ofVec3f> _verts;
|
||||||
|
vector<ofVec2f> _tex;
|
||||||
|
vector<unsigned int> _ind;
|
||||||
|
|
||||||
|
static ofxArcBall cam;
|
||||||
|
|
||||||
|
static ofShader _shader;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
#include "ofAppGlutWindow.h"
|
#include "ofAppGlutWindow.h"
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
|
|
||||||
#define SCREEN_WIDTH 1280
|
#define SCREEN_WIDTH 800
|
||||||
#define SCREEN_HEIGHT 800
|
#define SCREEN_HEIGHT 600
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
|||||||
+21
-11
@@ -7,10 +7,8 @@
|
|||||||
|
|
||||||
void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
||||||
|
|
||||||
meshIsComplete=false;
|
|
||||||
imageForContourAvailable=false;
|
|
||||||
|
|
||||||
_cam_w = camWidth; _cam_h = camHeight;
|
_cam_w = camWidth; _cam_h = camHeight;
|
||||||
|
|
||||||
if(RefractiveIndex::_mode == MODE_DRAWING) {
|
if(RefractiveIndex::_mode == MODE_DRAWING) {
|
||||||
ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true);
|
ofFileDialogResult r = ofSystemLoadDialog("choooose da folda", true);
|
||||||
if(!r.bSuccess) {
|
if(!r.bSuccess) {
|
||||||
@@ -22,6 +20,16 @@ void AbstractAnalysis::setup(int camWidth, int camHeight) {
|
|||||||
_whole_file_path_synthesis = r.filePath + "/darwings";
|
_whole_file_path_synthesis = r.filePath + "/darwings";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// viewport
|
||||||
|
|
||||||
|
tx = RefractiveIndex::XML.getValue("config:viewport:tx", 200.0);
|
||||||
|
ty = RefractiveIndex::XML.getValue("config:viewport:ty", 50.0);
|
||||||
|
tz = RefractiveIndex::XML.getValue("config:viewport:tz", -500.0);
|
||||||
|
|
||||||
|
rx = RefractiveIndex::XML.getValue("config:viewport:rx", 0.0);
|
||||||
|
ry = RefractiveIndex::XML.getValue("config:viewport:ry", 0.0);
|
||||||
|
rz = RefractiveIndex::XML.getValue("config:viewport:rz", 0.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the main threaded loop for a given analysis
|
// this is the main threaded loop for a given analysis
|
||||||
@@ -46,14 +54,13 @@ void AbstractAnalysis::do_synthesize() {
|
|||||||
if(_state == STATE_STOP) goto exit;
|
if(_state == STATE_STOP) goto exit;
|
||||||
_state = STATE_DISPLAY_RESULTS;
|
_state = STATE_DISPLAY_RESULTS;
|
||||||
displayresults();
|
displayresults();
|
||||||
cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MODE_DRAWING:
|
case MODE_DRAWING:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
ofxFileHelper fileHelperDrawing;
|
ofxFileHelper fileHelperDrawing;
|
||||||
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
|
if(!fileHelperDrawing.doesDirectoryExist(_whole_file_path_synthesis)){
|
||||||
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
|
fileHelperDrawing.makeDirectory(_whole_file_path_synthesis);
|
||||||
@@ -65,12 +72,14 @@ void AbstractAnalysis::do_synthesize() {
|
|||||||
if(_state == STATE_STOP) goto exit;
|
if(_state == STATE_STOP) goto exit;
|
||||||
_state = STATE_DISPLAY_RESULTS;
|
_state = STATE_DISPLAY_RESULTS;
|
||||||
displayresults();
|
displayresults();
|
||||||
cleanup();
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
cleanup();
|
cleanup();
|
||||||
|
ofxFileHelper::deleteFolder(_whole_file_path_analysis);
|
||||||
ofNotifyEvent(_synthesize_cb, _name);
|
ofNotifyEvent(_synthesize_cb, _name);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -122,6 +131,7 @@ void AbstractAnalysis::create_dir_allocate_images()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
|
_whole_file_path_synthesis = SYNTHESIS_PATH + RefractiveIndex::_location + "/" + _name + "/"+replaceTime;
|
||||||
|
|
||||||
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
|
if(!fileHelperSynthesis.doesDirectoryExist(_whole_file_path_synthesis)){
|
||||||
@@ -139,6 +149,7 @@ void AbstractAnalysis::create_dir_allocate_images()
|
|||||||
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
fileHelperSynthesis.makeDirectory(SYNTHESIS_PATH+RefractiveIndex::_location+"/"+_name+"/"+replaceTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
|
//////////////////////////////END DIRECTORY CREATION //////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +168,6 @@ void AbstractAnalysis::create_dir_allocate_images()
|
|||||||
myGrayImage1.setUseTexture(false);
|
myGrayImage1.setUseTexture(false);
|
||||||
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
|
myGrayImage1.allocate(RefractiveIndex::_vid_w, RefractiveIndex::_vid_h, OF_IMAGE_GRAYSCALE);
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
|
//////////////////////////////END ALLOCATE IMAGES //////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -182,9 +192,6 @@ void AbstractAnalysis::read_dir_create_list(string folder_path)
|
|||||||
for(int i = 0; i < list.size(); i++) {
|
for(int i = 0; i < list.size(); i++) {
|
||||||
string filepath = folder_path + "/" + list[i];
|
string filepath = folder_path + "/" + list[i];
|
||||||
_saved_filenames_analysis.push_back(filepath);
|
_saved_filenames_analysis.push_back(filepath);
|
||||||
|
|
||||||
cout << list[i] << endl;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,6 +204,7 @@ void AbstractAnalysis::saveImageAnalysis(string filename)
|
|||||||
if (RefractiveIndex::_vidGrabber.isFrameNew())
|
if (RefractiveIndex::_vidGrabber.isFrameNew())
|
||||||
{
|
{
|
||||||
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
|
RefractiveIndex::_pixels = RefractiveIndex::_vidGrabber.getPixelsRef(); //get ofPixels from the camera
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -228,6 +236,7 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
|
|||||||
|
|
||||||
#ifdef TARGET_OSX
|
#ifdef TARGET_OSX
|
||||||
|
|
||||||
|
|
||||||
ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
ofSaveImage(newPixels->getPixelsRef(), _whole_file_path_synthesis+"/"+filename, OF_IMAGE_QUALITY_BEST);
|
||||||
|
|
||||||
#elif defined(TARGET_WIN32)
|
#elif defined(TARGET_WIN32)
|
||||||
@@ -255,3 +264,4 @@ void AbstractAnalysis::saveImageSynthesis(string filename, ofxCvImage* newPixels
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-17
@@ -61,23 +61,6 @@ public:
|
|||||||
|
|
||||||
// event
|
// event
|
||||||
ofEvent<string> _synthesize_cb;
|
ofEvent<string> _synthesize_cb;
|
||||||
bool meshIsComplete;
|
|
||||||
bool imageForContourAvailable;
|
|
||||||
ofMesh aMesh;
|
|
||||||
ofLight light;
|
|
||||||
ofLight lightStatic;
|
|
||||||
|
|
||||||
string meshFileName;
|
|
||||||
//difference between our image size and the size of the fbo
|
|
||||||
float widthScaleFactor;
|
|
||||||
float heightScaleFactor;
|
|
||||||
ofImage contourImage;
|
|
||||||
ofPixels meshPix;
|
|
||||||
ofPixels publicColorImage;
|
|
||||||
float zPlaneAverage;
|
|
||||||
|
|
||||||
//added Tom 1/5/12 defines the stretch we make to the mesh to make it fit HD proportions
|
|
||||||
float _mesh_size_multiplier;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int _cam_w, _cam_h;
|
int _cam_w, _cam_h;
|
||||||
@@ -98,5 +81,9 @@ protected:
|
|||||||
int NUM_RUN;
|
int NUM_RUN;
|
||||||
int NUM_SAVE_PER_RUN;
|
int NUM_SAVE_PER_RUN;
|
||||||
|
|
||||||
|
//viewport
|
||||||
|
|
||||||
|
float tx, ty, tz, rx, ry, rz;
|
||||||
|
|
||||||
friend class AnalysisAdaptor;
|
friend class AnalysisAdaptor;
|
||||||
};
|
};
|
||||||
+66
-775
@@ -13,6 +13,13 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
|
|
||||||
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -21,62 +28,6 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN CamNoiseAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 8;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour = 6;
|
|
||||||
multiplier = 4.0;
|
|
||||||
|
|
||||||
ofSetLineWidth(5.0f);
|
|
||||||
glPointSize(5.0f);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
//blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
//blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
//blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
// meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
///setup light
|
|
||||||
ofEnableLighting();
|
|
||||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT0);
|
|
||||||
|
|
||||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT1);
|
|
||||||
glPointSize(9.0f);
|
|
||||||
glEnable(GL_POINT_SMOOTH);
|
|
||||||
glCullFace(GL_BACK);
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_camnoise", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_camnoise", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME CamNoiseAnalysis " << acq_run_time << endl;
|
||||||
@@ -103,49 +54,26 @@ void CamNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
|
||||||
cvGrayImage2.clear();
|
|
||||||
cvGrayDiff2.clear();
|
|
||||||
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
////---------
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
algo = RefractiveIndex::XML.getValue("config:algorithms:camnoise:algo", algo_default);
|
||||||
|
scale = RefractiveIndex::XML.getValue("config:algorithms:camnoise:scale", scale_default);
|
||||||
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:camnoise:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:camnoise:line_width", line_width_default);
|
||||||
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:camnoise:point_size", point_size_default);
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,160 +107,27 @@ void CamNoiseAnalysis::acquire()
|
|||||||
|
|
||||||
void CamNoiseAnalysis::synthesise()
|
void CamNoiseAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
//cout << "CamNoiseAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
_returnAveragePixelValues();
|
/*
|
||||||
vector<vector<float> > averagePixelBrightnessesForEachLevel = averagePixelValuesForAllLevels;
|
|
||||||
float lightLevel=0;
|
|
||||||
float pLightLevel=0;
|
|
||||||
cout<<_listOfLightLevels.size()<<" "<<averagePixelBrightnessesForEachLevel.size()<<" these should be the same";
|
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
vector<string> fileNameParts= ofSplitString(_saved_filenames_analysis[i], "_");
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
lightLevel = ofToFloat(fileNameParts[fileNameParts.size()-2]);
|
_RUN_DONE = false;
|
||||||
//cout << "CamNoiseAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
//find which list of average pixel values is for THIS light level
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
int _averagePixelVectorIndex;
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
for (int j=0; j<_listOfLightLevels.size(); j+=3) {
|
Thread::sleep(3);
|
||||||
if(lightLevel==_listOfLightLevels[j]){
|
*/
|
||||||
_averagePixelVectorIndex=j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
// cout << "LOADED image1!!!" << endl;
|
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
/* cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
|
||||||
//cvGrayDiff1.erode();
|
|
||||||
|
|
||||||
cvGrayImage1.dilate();
|
|
||||||
cvGrayImage1.blur(5);
|
|
||||||
cvGrayImage1.contrastStretch();
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
*/
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, averagePixelBrightnessesForEachLevel[_averagePixelVectorIndex], _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_CamNoiseAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CamNoiseAnalysis::displayresults()
|
void CamNoiseAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
@@ -343,13 +138,15 @@ void CamNoiseAnalysis::displayresults()
|
|||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -511,8 +308,6 @@ void CamNoiseAnalysis::draw()
|
|||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
|
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -521,21 +316,47 @@ void CamNoiseAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
glPointSize(point_size);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
//cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -556,533 +377,3 @@ void CamNoiseAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CamNoiseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//to do
|
|
||||||
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(chooseColour==6){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x++;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> CamNoiseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, vector<float> averageDepths, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
int inc=0;
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
|
|
||||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
|
||||||
|
|
||||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
|
||||||
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
if(i<100){
|
|
||||||
|
|
||||||
// cout<<" average: "<<averageDepths[inc]<<" actual: "<<imageColor1.getBrightness()<<" ";
|
|
||||||
}
|
|
||||||
// int thisDiff=imageColor1.getBrightness();
|
|
||||||
|
|
||||||
int thisDiff=-(imageColor1.getBrightness() - averageDepths[inc] );
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
inc++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CamNoiseAnalysis:: _returnAveragePixelValues(){
|
|
||||||
|
|
||||||
|
|
||||||
//second number in 15_204.00_2.jpg is the light level
|
|
||||||
|
|
||||||
float lightLevel=0;
|
|
||||||
float pLightLevel=0;
|
|
||||||
float numberOfImagesActuallyLoaded=0;
|
|
||||||
vector<float> averagePixelValuesForOneLevel;
|
|
||||||
|
|
||||||
for (int j=0; j<RefractiveIndex::_vid_w*RefractiveIndex::_vid_h; j++) {
|
|
||||||
averagePixelValuesForOneLevel.push_back(0.0);
|
|
||||||
}
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
|
|
||||||
//split file name by under score
|
|
||||||
vector<string> fileNameParts= ofSplitString(_saved_filenames_analysis[i], "_");
|
|
||||||
|
|
||||||
lightLevel = ofToFloat(fileNameParts[fileNameParts.size()-2]);
|
|
||||||
// cout<<" lightLevel "<<lightLevel;
|
|
||||||
|
|
||||||
ofPixels image1Pixels=image1.getPixelsRef();
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
int inc=0;
|
|
||||||
for (int j=0; j<image1Pixels.size(); j+=3) {
|
|
||||||
ofColor color=image1Pixels.getColor(x, y);
|
|
||||||
averagePixelValuesForOneLevel[inc]+= color.getBrightness();
|
|
||||||
x++;
|
|
||||||
inc++;
|
|
||||||
if(x>=image1Pixels.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// _listOfLightLevels}
|
|
||||||
numberOfImagesActuallyLoaded++;
|
|
||||||
|
|
||||||
//if this is a new light level advance
|
|
||||||
if (lightLevel!=pLightLevel) {
|
|
||||||
|
|
||||||
///check that this light level is not already in our list
|
|
||||||
|
|
||||||
|
|
||||||
_listOfLightLevels.push_back(lightLevel);
|
|
||||||
|
|
||||||
for (int j=0; j<averagePixelValuesForOneLevel.size(); j++) {
|
|
||||||
averagePixelValuesForOneLevel[j]/=numberOfImagesActuallyLoaded;
|
|
||||||
//cout<<" "<<averagePixelValuesForOneLevel[j]<<" ";
|
|
||||||
}
|
|
||||||
averagePixelValuesForAllLevels.push_back(averagePixelValuesForOneLevel);
|
|
||||||
for (int j=0; j<averagePixelValuesForOneLevel.size(); j++) {
|
|
||||||
averagePixelValuesForOneLevel[j]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pLightLevel=lightLevel;
|
|
||||||
numberOfImagesActuallyLoaded=0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int j=0;j<_listOfLightLevels.size();j++){
|
|
||||||
//cout<<_listOfLightLevels[j]<<" lightlevel ";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-46
@@ -37,53 +37,13 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
|
||||||
ofxCvColorImage cvColorImage2;
|
|
||||||
ofxCvColorImage cvColorImage3;
|
|
||||||
ofxCvColorImage cvColorImage4;
|
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, vector<float> averageDepths, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
//returns a vector of floats for each distinct light level
|
|
||||||
void _returnAveragePixelValues();
|
|
||||||
//this vector of vectors will be returned
|
|
||||||
vector<vector<float> > averagePixelValuesForAllLevels;
|
|
||||||
|
|
||||||
vector<float> _listOfLightLevels;
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
|
|
||||||
|
int algo;
|
||||||
|
int scale;
|
||||||
|
int draw_style;
|
||||||
|
float line_width;
|
||||||
|
float point_size;
|
||||||
};
|
};
|
||||||
|
|||||||
+67
-339
@@ -12,6 +12,11 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const float line_width_default = 0.5f;
|
||||||
|
|
||||||
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -20,14 +25,6 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ColorMultiAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
|
|
||||||
_mesh_size_multiplier=8;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour=1;
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ColorMultiAnalysis " << acq_run_time << endl;
|
||||||
@@ -54,50 +51,21 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
////---------
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
algo = RefractiveIndex::XML.getValue("config:algorithms:colormulti:algo", algo_default);
|
||||||
cvGrayImage2.clear();
|
scale = RefractiveIndex::XML.getValue("config:algorithms:colormulti:scale", scale_default);
|
||||||
cvGrayDiff2.clear();
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:colormulti:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:colormulti:line_width", line_width_default);
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,124 +101,25 @@ void ColorMultiAnalysis::acquire()
|
|||||||
void ColorMultiAnalysis::synthesise()
|
void ColorMultiAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
|
|
||||||
//cout << "ColorMultiAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
//cout << "ColorMultiAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
//cvColorImage1.blur(1);
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 15, 15);
|
|
||||||
cvXorS( cvColorImage1.getCvImage(), cvScalarAll(2), cvColorImage1.getCvImage(), 0 );
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
/*
|
||||||
_RUN_DONE = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
meshIsComplete=false;
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
_synth_save_cnt=0;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
_RUN_DONE = false;
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
Thread::sleep(3);
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorMultiAnalysis::displayresults()
|
void ColorMultiAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
@@ -261,13 +130,15 @@ void ColorMultiAnalysis::displayresults()
|
|||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -279,27 +150,6 @@ void ColorMultiAnalysis::displayresults()
|
|||||||
void ColorMultiAnalysis::draw()
|
void ColorMultiAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
ofEnableSmoothing();
|
|
||||||
|
|
||||||
ofEnableLighting();
|
|
||||||
ofEnableSeparateSpecularLight();
|
|
||||||
light.enable();
|
|
||||||
|
|
||||||
light.setPosition(200,200,-150);
|
|
||||||
lightStatic.enable();
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
ofSetLineWidth(2.0f);
|
|
||||||
//glPointSize(4.0f);
|
|
||||||
|
|
||||||
ofEnableBlendMode ( OF_BLENDMODE_ADD );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_ALPHA );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_SCREEN );
|
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -430,8 +280,9 @@ void ColorMultiAnalysis::draw()
|
|||||||
_anim_cnt++;
|
_anim_cnt++;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_state = STATE_DISPLAY_RESULTS;
|
//_state = STATE_DISPLAY_RESULTS;
|
||||||
_anim_cnt=0;
|
_anim_cnt=0;
|
||||||
|
_RUN_DONE = true;
|
||||||
}
|
}
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
ofSetRectMode(OF_RECTMODE_CORNER);
|
ofSetRectMode(OF_RECTMODE_CORNER);
|
||||||
@@ -445,7 +296,6 @@ void ColorMultiAnalysis::draw()
|
|||||||
|
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -454,22 +304,48 @@ void ColorMultiAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
if (_show_image)
|
|
||||||
{
|
|
||||||
//cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
//RefractiveIndex::cam.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofTranslate(tx, ty, tz);
|
||||||
}
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
// display results of the synthesis
|
if (_show_image)
|
||||||
_RUN_DONE = true;
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
break;
|
|
||||||
|
image2.bind();
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.begin();
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.end();
|
||||||
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
|
_RUN_DONE = true;
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,156 +361,8 @@ void ColorMultiAnalysis::draw()
|
|||||||
void ColorMultiAnalysis::save_cb(Timer& timer)
|
void ColorMultiAnalysis::save_cb(Timer& timer)
|
||||||
{
|
{
|
||||||
_save_cnt++;
|
_save_cnt++;
|
||||||
|
|
||||||
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorMultiAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
|
|
||||||
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINES);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINE_STRIP);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINE_LOOP);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_POINTS);
|
|
||||||
|
|
||||||
/*
|
|
||||||
OF_PRIMITIVE_TRIANGLES,
|
|
||||||
OF_PRIMITIVE_TRIANGLE_STRIP,
|
|
||||||
OF_PRIMITIVE_TRIANGLE_FAN,
|
|
||||||
OF_PRIMITIVE_LINES,
|
|
||||||
OF_PRIMITIVE_LINE_STRIP,
|
|
||||||
OF_PRIMITIVE_LINE_LOOP,
|
|
||||||
OF_PRIMITIVE_POINTS
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> ColorMultiAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
//float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
//float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
|
||||||
//float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
float multiplier=15.0*((thisDiff)/255.0);
|
|
||||||
|
|
||||||
differences.push_back(multiplier* thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -31,45 +31,14 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
int algo;
|
||||||
ofxCvColorImage cvColorImage2;
|
int scale;
|
||||||
ofxCvColorImage cvColorImage3;
|
int draw_style;
|
||||||
ofxCvColorImage cvColorImage4;
|
float line_width;
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+66
-489
@@ -1,11 +1,9 @@
|
|||||||
#include "ColorSingleAnalysis.h"
|
#include "ColorSingleAnalysis.h"
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
|
|
||||||
#include "Poco/Timer.h"
|
#include "Poco/Timer.h"
|
||||||
#include "Poco/Thread.h"
|
#include "Poco/Thread.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "RefractiveIndex.h"
|
#include "RefractiveIndex.h"
|
||||||
|
|
||||||
using Poco::Timer;
|
using Poco::Timer;
|
||||||
@@ -15,6 +13,11 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const float line_width_default = 0.5f;
|
||||||
|
|
||||||
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -23,18 +26,10 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ColorSingleAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier=8;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour=1;
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ColorSingleAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
//int acq_run_time = 25; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 1*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
@@ -57,62 +52,34 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight)
|
|||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
fileNameTag = "";
|
fileNameTag = "";
|
||||||
fileNameColor = "";
|
|
||||||
|
|
||||||
_show_image = false;
|
_show_image = false;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
////---------
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
algo = RefractiveIndex::XML.getValue("config:algorithms:colorsingle:algo", algo_default);
|
||||||
cvGrayImage2.clear();
|
scale = RefractiveIndex::XML.getValue("config:algorithms:colorsingle:scale", scale_default);
|
||||||
cvGrayDiff2.clear();
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:colorsingle:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:colorsingle:line_width", line_width_default);
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorSingleAnalysis::acquire()
|
void ColorSingleAnalysis::acquire()
|
||||||
{
|
{
|
||||||
|
|
||||||
Timer* save_timer;
|
Timer* save_timer;
|
||||||
|
|
||||||
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
|
TimerCallback<ColorSingleAnalysis> save_callback(*this, &ColorSingleAnalysis::save_cb);
|
||||||
@@ -135,156 +102,33 @@ void ColorSingleAnalysis::acquire()
|
|||||||
|
|
||||||
save_timer->stop();
|
save_timer->stop();
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorSingleAnalysis::synthesise()
|
void ColorSingleAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
|
|
||||||
//cout << "ColorSingleAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
//cout << "ColorSingleAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
cout << "_saved_filenames_analysis[i].find(RED): " << _saved_filenames_analysis[i].find("RED") << endl;
|
|
||||||
|
|
||||||
if(_saved_filenames_analysis[i].find("RED")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameColor = "RED";
|
|
||||||
cout<<"FOUND RED"<<endl;
|
|
||||||
} else if (_saved_filenames_analysis[i].find("GREEN")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameColor = "GREEN";
|
|
||||||
cout<<"FOUND GREEN"<<endl;
|
|
||||||
} else if(_saved_filenames_analysis[i].find("BLUE")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameColor = "BLUE";
|
|
||||||
cout<<"FOUND BLUE"<<endl;
|
|
||||||
} else if(_saved_filenames_analysis[i].find("FADING")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameColor = "FADING";
|
|
||||||
cout<<"FOUND FADING"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
cvColorImage1.blur(1);
|
|
||||||
|
|
||||||
//cvSmooth( cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), CV_GAUSSIAN, 9, 9 );
|
|
||||||
|
|
||||||
cvColorImage1.erode();
|
|
||||||
|
|
||||||
cvSmooth( cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), CV_GAUSSIAN, 3, 3 );
|
|
||||||
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(255), cvColorImage1.getCvImage(), 0 );
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorSingleAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
/*
|
||||||
_RUN_DONE = true;
|
|
||||||
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
_RUN_DONE = false;
|
||||||
|
|
||||||
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
meshIsComplete=false;
|
|
||||||
_synth_save_cnt=0;
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(3);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorSingleAnalysis::displayresults()
|
void ColorSingleAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
@@ -295,13 +139,15 @@ void ColorSingleAnalysis::displayresults()
|
|||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -313,31 +159,12 @@ void ColorSingleAnalysis::displayresults()
|
|||||||
|
|
||||||
void ColorSingleAnalysis::draw()
|
void ColorSingleAnalysis::draw()
|
||||||
{
|
{
|
||||||
ofEnableSmoothing();
|
|
||||||
|
|
||||||
ofEnableLighting();
|
|
||||||
ofEnableSeparateSpecularLight();
|
|
||||||
light.enable();
|
|
||||||
|
|
||||||
light.setPosition(200,200,-150);
|
|
||||||
lightStatic.enable();
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
ofSetLineWidth(1.0f);
|
|
||||||
glPointSize(1.0f);
|
|
||||||
|
|
||||||
ofEnableBlendMode ( OF_BLENDMODE_ADD );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_ALPHA );
|
|
||||||
//ofEnableBlendMode ( OF_BLENDMODE_SCREEN );
|
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt < _frame_cnt_max)
|
if (_frame_cnt < _frame_cnt_max)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -485,7 +312,6 @@ void ColorSingleAnalysis::draw()
|
|||||||
|
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -494,20 +320,46 @@ void ColorSingleAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
//cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -529,278 +381,3 @@ void ColorSingleAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ColorSingleAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINES);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINE_STRIP);
|
|
||||||
//mesh.setMode(OF_PRIMITIVE_LINE_LOOP);
|
|
||||||
mesh.setMode(OF_PRIMITIVE_POINTS);
|
|
||||||
|
|
||||||
/*
|
|
||||||
OF_PRIMITIVE_TRIANGLES,
|
|
||||||
OF_PRIMITIVE_TRIANGLE_STRIP,
|
|
||||||
OF_PRIMITIVE_TRIANGLE_FAN,
|
|
||||||
OF_PRIMITIVE_LINES,
|
|
||||||
OF_PRIMITIVE_LINE_STRIP,
|
|
||||||
OF_PRIMITIVE_LINE_LOOP,
|
|
||||||
OF_PRIMITIVE_POINTS
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255, 255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
if(fileNameColor=="RED")
|
|
||||||
{
|
|
||||||
currentSecondImageColor.r=255;
|
|
||||||
currentSecondImageColor.g=0;
|
|
||||||
currentSecondImageColor.b=0;
|
|
||||||
currentSecondImageColor.a=255;
|
|
||||||
|
|
||||||
} else if(fileNameColor=="GREEN")
|
|
||||||
{
|
|
||||||
currentSecondImageColor.r=0;
|
|
||||||
currentSecondImageColor.g=255;
|
|
||||||
currentSecondImageColor.b=0;
|
|
||||||
currentSecondImageColor.a=255;
|
|
||||||
|
|
||||||
} else if(fileNameColor=="BLUE")
|
|
||||||
{
|
|
||||||
currentSecondImageColor.r=0;
|
|
||||||
currentSecondImageColor.g=0;
|
|
||||||
currentSecondImageColor.b=255;
|
|
||||||
currentSecondImageColor.a=255;
|
|
||||||
|
|
||||||
} else if(fileNameColor=="FADING")
|
|
||||||
{
|
|
||||||
currentSecondImageColor.r= 255;
|
|
||||||
currentSecondImageColor.g= 255;
|
|
||||||
currentSecondImageColor.b= 255;
|
|
||||||
currentSecondImageColor.a= 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
//x++;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//y++;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff;
|
|
||||||
|
|
||||||
if(fileNameColor=="RED")
|
|
||||||
{
|
|
||||||
//thisDiff=abs(imageColor1.r);
|
|
||||||
|
|
||||||
thisDiff=abs(255-imageColor1.r);
|
|
||||||
} else if(fileNameColor=="GREEN")
|
|
||||||
{
|
|
||||||
//thisDiff=abs(imageColor1.g);
|
|
||||||
|
|
||||||
thisDiff=abs(255-imageColor1.g);
|
|
||||||
|
|
||||||
} else if(fileNameColor=="BLUE")
|
|
||||||
{
|
|
||||||
//thisDiff=abs(imageColor1.b);
|
|
||||||
|
|
||||||
thisDiff=abs(255-imageColor1.b);
|
|
||||||
|
|
||||||
} else if(fileNameColor=="FADING") {
|
|
||||||
|
|
||||||
//thisDiff=imageColor1.getBrightness();
|
|
||||||
thisDiff=255-imageColor1.getBrightness();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
float multiplier=8.0;
|
|
||||||
|
|
||||||
differences.push_back(multiplier* thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
~ author: dviid
|
~ author: dviid
|
||||||
~ contact: dviid@labs.ciid.dk
|
~ contact: dviid@labs.ciid.dk
|
||||||
*/
|
*/
|
||||||
@@ -32,53 +32,19 @@ protected:
|
|||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
string fileNameTag;
|
string fileNameTag;
|
||||||
string fileNameColor;
|
|
||||||
float r,g,b;
|
float r,g,b;
|
||||||
|
|
||||||
int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt;
|
int _run_cnt, _save_cnt, _fade_cnt, _synth_save_cnt, _anim_cnt;
|
||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
int algo;
|
||||||
ofxCvColorImage cvColorImage2;
|
int scale;
|
||||||
ofxCvColorImage cvColorImage3;
|
int draw_style;
|
||||||
ofxCvColorImage cvColorImage4;
|
float line_width;
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvFloatImage cvFloatImage1;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+63
-648
@@ -13,37 +13,20 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
|
|
||||||
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
|
NUM_RUN = RefractiveIndex::XML.getValue("config:analysis_NUM_RUN:NUM_RUN_diffnoise", NUMBER_RUNS);
|
||||||
|
|
||||||
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN DiffNoiseAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 10;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour = 5;
|
|
||||||
multiplier = 4.0;
|
|
||||||
|
|
||||||
blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
//blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
//blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
//blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_diffnoise", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_diffnoise", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME DiffNoiseAnalysis " << acq_run_time << endl;
|
||||||
@@ -70,50 +53,23 @@ void DiffNoiseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
////---------
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
algo = RefractiveIndex::XML.getValue("config:algorithms:diffnoise:algo", algo_default);
|
||||||
cvGrayImage2.clear();
|
scale = RefractiveIndex::XML.getValue("config:algorithms:diffnoise:scale", scale_default);
|
||||||
cvGrayDiff2.clear();
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:diffnoise:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:diffnoise:line_width", line_width_default);
|
||||||
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:diffnoise:point_size", point_size_default);
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,167 +104,27 @@ void DiffNoiseAnalysis::acquire()
|
|||||||
void DiffNoiseAnalysis::synthesise()
|
void DiffNoiseAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
|
|
||||||
//cout << "DiffNoiseAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
//cout << "DiffNoiseAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
//cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
|
|
||||||
//cvColorImage1.blur(5);
|
|
||||||
//cvColorImage2.blur(5);
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
//cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayImage1.convertToRange(0.0, 255.0);
|
|
||||||
//cvGrayImage2.convertToRange(0.0, 255.0);
|
|
||||||
|
|
||||||
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
|
||||||
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
|
||||||
|
|
||||||
//cvGrayImage1.contrastStretch();
|
|
||||||
//cvGrayImage2.contrastStretch();
|
|
||||||
|
|
||||||
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
|
||||||
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
|
||||||
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
//image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_DiffNoiseAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
//}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
/*
|
||||||
_RUN_DONE = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
meshIsComplete=false;
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
_synth_save_cnt=0;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
_RUN_DONE = false;
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
Thread::sleep(3);
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffNoiseAnalysis::displayresults()
|
void DiffNoiseAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
@@ -319,46 +135,27 @@ void DiffNoiseAnalysis::displayresults()
|
|||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this runs at frame rate = 33 ms for 30 FPS
|
// this runs at frame rate = 33 ms for 30 FPS
|
||||||
void DiffNoiseAnalysis::draw()
|
void DiffNoiseAnalysis::draw()
|
||||||
{
|
{
|
||||||
ofEnableSmoothing();
|
|
||||||
|
|
||||||
ofEnableLighting();
|
|
||||||
ofEnableSeparateSpecularLight();
|
|
||||||
light.setPointLight();
|
|
||||||
|
|
||||||
light.enable();
|
|
||||||
lightStatic.enable();
|
|
||||||
|
|
||||||
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
|
||||||
|
|
||||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
ofSetLineWidth(1.0f);
|
|
||||||
glPointSize(5.0f);
|
|
||||||
|
|
||||||
ofEnableBlendMode(blendMode);
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -405,6 +202,7 @@ void DiffNoiseAnalysis::draw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
|
if (_frame_cnt >= (_frame_cnt_max-_fade_in_frames) && _frame_cnt <= _frame_cnt_max) {
|
||||||
|
|
||||||
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
|
for (int i=1; i < ofGetHeight() ; i=i+rectSize)
|
||||||
@@ -521,9 +319,6 @@ void DiffNoiseAnalysis::draw()
|
|||||||
|
|
||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -532,22 +327,47 @@ void DiffNoiseAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
glPointSize(point_size);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
//cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
//image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_GRAYSCALE);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -565,408 +385,3 @@ void DiffNoiseAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DiffNoiseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> DiffNoiseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
|
||||||
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|||||||
+6
-39
@@ -36,47 +36,14 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
int algo;
|
||||||
ofxCvColorImage cvColorImage2;
|
int scale;
|
||||||
ofxCvColorImage cvColorImage3;
|
int draw_style;
|
||||||
ofxCvColorImage cvColorImage4;
|
float line_width;
|
||||||
ofxCvColorImage cvColorImage5;
|
float point_size;
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+68
-254
@@ -13,6 +13,13 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
|
|
||||||
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
void IResponseAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -21,21 +28,10 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN IResponseAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
|
|
||||||
_mesh_size_multiplier=4;
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_iresponse", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME IResponseAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
|
|
||||||
_mesh_size_multiplier=8;
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
||||||
|
|
||||||
@@ -58,50 +54,28 @@ void IResponseAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
////---------
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
algo = RefractiveIndex::XML.getValue("config:algorithms:iresponse:algo", algo_default);
|
||||||
cvGrayImage2.clear();
|
scale = RefractiveIndex::XML.getValue("config:algorithms:iresponse:scale", scale_default);
|
||||||
cvGrayDiff2.clear();
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:iresponse:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:iresponse:line_width", line_width_default);
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:iresponse:point_size", point_size_default);
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IResponseAnalysis::acquire()
|
void IResponseAnalysis::acquire()
|
||||||
{
|
{
|
||||||
|
|
||||||
Timer* save_timer;
|
Timer* save_timer;
|
||||||
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
|
TimerCallback<IResponseAnalysis> save_callback(*this, &IResponseAnalysis::save_cb);
|
||||||
|
|
||||||
@@ -129,92 +103,28 @@ void IResponseAnalysis::acquire()
|
|||||||
|
|
||||||
void IResponseAnalysis::synthesise()
|
void IResponseAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
cout<<"SYNTHESISING IRESPONSE";
|
|
||||||
|
|
||||||
//cout << "IResponseAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
//cout << "IResponseAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
//cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
//if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//background subtraction//
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//meshPix=make3DZmap(image1, image5, _background);
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_IResponseSynthesis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
/*
|
||||||
_RUN_DONE = true;
|
|
||||||
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
_RUN_DONE = false;
|
||||||
|
|
||||||
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
meshIsComplete=false;
|
|
||||||
_synth_save_cnt=0;
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void IResponseAnalysis::displayresults()
|
void IResponseAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
@@ -225,13 +135,15 @@ void IResponseAnalysis::displayresults()
|
|||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
// cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -372,8 +284,6 @@ void IResponseAnalysis::draw()
|
|||||||
|
|
||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
//cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -382,21 +292,47 @@ void IResponseAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
glPointSize(point_size);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
//cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -416,125 +352,3 @@ void IResponseAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IResponseAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,0,0);
|
|
||||||
|
|
||||||
int chooseColour=1 ;
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x++;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<float> IResponseAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//the current version compares how bright this pixel is with how bright it would be following inverse square fall off from centre
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
|
||||||
|
|
||||||
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
|
||||||
|
|
||||||
//float _presumedBrightness=255;
|
|
||||||
|
|
||||||
int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
float multiplier=4.0;
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-27
@@ -35,35 +35,14 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
int algo;
|
||||||
ofxCvColorImage cvColorImage2;
|
int scale;
|
||||||
ofxCvColorImage cvColorImage3;
|
int draw_style;
|
||||||
ofxCvColorImage cvColorImage4;
|
float line_width;
|
||||||
ofxCvColorImage cvColorImage5;
|
float point_size;
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
//returns ofPixels but these pixels actually hold depth data.
|
|
||||||
//ofPixels make3DZmap(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
};
|
};
|
||||||
|
|||||||
+69
-681
@@ -12,8 +12,12 @@ using Poco::Thread;
|
|||||||
|
|
||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
#define TRESHOLD 80
|
|
||||||
#define MAXBLOBS 15
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
@@ -23,41 +27,10 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN RelaxRateAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 8;
|
|
||||||
vertexSubsampling_x = 1; //must be at least '1'
|
|
||||||
vertexSubsampling_y = 5; //must be at least '1'
|
|
||||||
chooseColour = 2;
|
|
||||||
multiplier = 4.0;
|
|
||||||
|
|
||||||
//blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
//blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
//blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_relaxrate", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME RelaxRateAnalysis " << acq_run_time << endl;
|
||||||
|
|
||||||
_treshold = RefractiveIndex::XML.getValue("config:relaxrate:treshold", TRESHOLD);
|
|
||||||
cout << "TRESHOLD RelaxRateAnalysis " << _treshold << endl;
|
|
||||||
|
|
||||||
_maxblobs = RefractiveIndex::XML.getValue("config:relaxrate:maxblobs", MAXBLOBS);
|
|
||||||
cout << "MAXBLOBS RelaxRateAnalysis " << _maxblobs << endl;
|
|
||||||
|
|
||||||
|
|
||||||
//int acq_run_time = 20; // 20 seconds of acquiring per run
|
|
||||||
|
|
||||||
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
DELTA_T_SAVE = 2*(10*acq_run_time/2); // for 20 seconds, we want this to be around 200 files
|
||||||
// or 10 times per second = every 100 ms
|
// or 10 times per second = every 100 ms
|
||||||
|
|
||||||
@@ -80,45 +53,22 @@ void RelaxRateAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
|
||||||
cvGrayImage2.clear();
|
|
||||||
cvGrayDiff2.clear();
|
|
||||||
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
////---------
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
|
algo = RefractiveIndex::XML.getValue("config:algorithms:relaxrate:algo", algo_default);
|
||||||
|
scale = RefractiveIndex::XML.getValue("config:algorithms:relaxrate:scale", scale_default);
|
||||||
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:relaxrate:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:relaxrate:line_width", line_width_default);
|
||||||
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:relaxrate:point_size", point_size_default);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,189 +102,47 @@ void RelaxRateAnalysis::acquire()
|
|||||||
|
|
||||||
void RelaxRateAnalysis::synthesise()
|
void RelaxRateAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
// cout << "RelaxRate::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
_RUN_DONE = false;
|
||||||
|
|
||||||
// cout << "StrobeAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
// cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
|
|
||||||
cvColorImage1.blur(1);
|
|
||||||
cvColorImage2.blur(1);
|
|
||||||
|
|
||||||
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayImage1.convertToRange(0.0, 255.0);
|
|
||||||
//cvGrayImage2.convertToRange(0.0, 255.0);
|
|
||||||
|
|
||||||
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
|
||||||
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
|
||||||
|
|
||||||
//cvGrayImage1.contrastStretch();
|
|
||||||
//cvGrayImage2.contrastStretch();
|
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage1, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvGrayDiff1.brightnessContrast(1.0,0.5);
|
|
||||||
|
|
||||||
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
|
||||||
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
|
||||||
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_RelaxRateAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
|
||||||
_RUN_DONE = true;
|
|
||||||
*/
|
|
||||||
|
|
||||||
meshIsComplete=false;
|
|
||||||
_synth_save_cnt=0;
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
Thread::sleep(10);
|
Thread::sleep(3);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RelaxRateAnalysis::displayresults()
|
void RelaxRateAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||||
|
|
||||||
while(!_image_shown){
|
while(!_image_shown){
|
||||||
Thread::sleep(2);
|
Thread::sleep(2);
|
||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
// cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -348,24 +156,6 @@ void RelaxRateAnalysis::displayresults()
|
|||||||
void RelaxRateAnalysis::draw()
|
void RelaxRateAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
ofEnableSmoothing();
|
|
||||||
|
|
||||||
ofEnableLighting();
|
|
||||||
ofEnableSeparateSpecularLight();
|
|
||||||
light.setPointLight();
|
|
||||||
|
|
||||||
light.enable();
|
|
||||||
lightStatic.enable();
|
|
||||||
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
|
||||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
ofSetLineWidth(2.0f);
|
|
||||||
glPointSize(1.0f);
|
|
||||||
|
|
||||||
ofEnableBlendMode(blendMode);
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -499,16 +289,47 @@ void RelaxRateAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
if (_show_image)
|
ofEnableAlphaBlending();
|
||||||
{
|
glShadeModel(GL_SMOOTH);
|
||||||
for(int i=0;i<cvContourFinderVectDisplay.size();i++){
|
glLineWidth(line_width);
|
||||||
cvContourFinderVectDisplay[i]->draw(0,0, ofGetWidth(), ofGetHeight());
|
glPointSize(point_size);
|
||||||
}
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
|
if (_show_image)
|
||||||
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
|
|
||||||
|
image2.bind();
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.begin();
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -527,438 +348,5 @@ void RelaxRateAnalysis::save_cb(Timer& timer)
|
|||||||
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
string file_name = ofToString(_save_cnt,2)+"_"+ ofToString(c,2)+"_"+ofToString(_run_cnt,2)+".jpg";
|
||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RelaxRateAnalysis::cleanup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void RelaxRateAnalysis::clearcfindervect()
|
|
||||||
{
|
|
||||||
for(int i = 0; i < cvContourFinderVect.size(); i++) {
|
|
||||||
rfiCvContourFinder* f = cvContourFinderVect[i];
|
|
||||||
|
|
||||||
// maybe it's erase here? http://forum.openframeworks.cc/index.php/topic,3016.0.html
|
|
||||||
// cvContourFinderVect.erase(i);
|
|
||||||
|
|
||||||
delete f;
|
|
||||||
}
|
|
||||||
cvContourFinderVect.clear();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void RelaxRateAnalysis::clearcfindervectdisplay()
|
|
||||||
{
|
|
||||||
cvContourFinderVectDisplay.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RelaxRateAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling_x;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling_y;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling_x;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling_y;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling_x;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling_y;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling_x;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling_y;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling_x;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling_y;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> RelaxRateAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
|
||||||
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-42
@@ -23,7 +23,6 @@ public:
|
|||||||
void acquire();
|
void acquire();
|
||||||
void synthesise();
|
void synthesise();
|
||||||
void displayresults();
|
void displayresults();
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
@@ -31,8 +30,6 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void clearcfindervect();
|
|
||||||
void clearcfindervectdisplay();
|
|
||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
float _flip, _level;
|
float _flip, _level;
|
||||||
@@ -46,45 +43,11 @@ protected:
|
|||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
|
||||||
ofxCvColorImage cvColorImage2;
|
|
||||||
ofxCvColorImage cvColorImage3;
|
|
||||||
ofxCvColorImage cvColorImage4;
|
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
|
|
||||||
vector<rfiCvContourFinder*> cvContourFinderVect;
|
|
||||||
vector<rfiCvContourFinder*> cvContourFinderVectDisplay;
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling_x;
|
|
||||||
int vertexSubsampling_y;
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
|
int algo;
|
||||||
|
int scale;
|
||||||
|
int draw_style;
|
||||||
|
float line_width;
|
||||||
|
float point_size;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+71
-651
@@ -17,6 +17,11 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const double line_width_default = 0.5;
|
||||||
|
|
||||||
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -25,57 +30,6 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ShadowScapesAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 8;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour = 5;
|
|
||||||
multiplier = 4.0;
|
|
||||||
|
|
||||||
ofSetLineWidth(5.0f);
|
|
||||||
glPointSize(5.0f);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
//blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
//blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
//blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
///setup light
|
|
||||||
ofEnableLighting();
|
|
||||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT0);
|
|
||||||
|
|
||||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT1);
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shadowscapes", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ShadowScapesAnalysis " << acq_run_time << endl;
|
||||||
@@ -93,7 +47,7 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
DELTA_T_SAVE = 3*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files
|
DELTA_T_SAVE = 3*(10*acq_run_time/2); // for 20 seconds, we want this to be around 100 files
|
||||||
// or 5 times per second = every 200 ms
|
// or 5 times per second = every 200 ms
|
||||||
|
|
||||||
_scanLineWidth = 100.0;
|
_scanLineWidth = 300.0;
|
||||||
_run_cnt = 0;
|
_run_cnt = 0;
|
||||||
_save_cnt = 0;
|
_save_cnt = 0;
|
||||||
_synth_save_cnt = 0;
|
_synth_save_cnt = 0;
|
||||||
@@ -106,48 +60,21 @@ void ShadowScapesAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
//cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
//cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
|
||||||
cvGrayImage2.clear();
|
|
||||||
cvGrayDiff2.clear();
|
|
||||||
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
////---------
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
|
algo = RefractiveIndex::XML.getValue("config:algorithms:shadowscapes:algo", algo_default);
|
||||||
|
scale = RefractiveIndex::XML.getValue("config:algorithms:shadowscapes:scale", scale_default);
|
||||||
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:shadowscapes:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:shadowscapes:line_width", line_width_default);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,167 +102,50 @@ void ShadowScapesAnalysis::acquire()
|
|||||||
|
|
||||||
void ShadowScapesAnalysis::synthesise()
|
void ShadowScapesAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
//cout << "ShadowScapesAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1; i++){
|
/*
|
||||||
|
|
||||||
// cout << "ShadowScapesAnalysis::synthesis FOR LOOP...\n";
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
_RUN_DONE = false;
|
||||||
|
|
||||||
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ShadowScapesAnalysis::displayresults()
|
||||||
|
{
|
||||||
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||||
|
|
||||||
|
while(!_image_shown){
|
||||||
|
Thread::sleep(2);
|
||||||
|
//cout << "!_image_shown" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
// cout << "LOADED image1!!!" << endl;
|
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
|
||||||
//cvGrayDiff1.erode();
|
|
||||||
|
|
||||||
cvGrayImage1.dilate();
|
|
||||||
cvGrayImage1.blur(5);
|
|
||||||
cvGrayImage1.contrastStretch();
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShadowScapeAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ShadowScapesAnalysis::displayresults()
|
|
||||||
{
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
|
||||||
|
|
||||||
while(!_image_shown){
|
|
||||||
Thread::sleep(2);
|
|
||||||
//cout << "!_image_shown" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -523,27 +333,47 @@ void ShadowScapesAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
// cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
|
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
|
||||||
|
|
||||||
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
|
|
||||||
// clear allocated memory...?
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,413 +406,3 @@ void ShadowScapesAnalysis::save_cb(Timer& timer)
|
|||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ShadowScapesAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> ShadowScapesAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
|
|
||||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
|
||||||
|
|
||||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
|
||||||
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,44 +42,13 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
|
||||||
ofxCvColorImage cvColorImage2;
|
|
||||||
ofxCvColorImage cvColorImage3;
|
|
||||||
ofxCvColorImage cvColorImage4;
|
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
|
int algo;
|
||||||
|
int scale;
|
||||||
|
int draw_style;
|
||||||
|
double line_width;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -13,6 +13,13 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 20
|
#define ACQUIRE_TIME 20
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
|
|
||||||
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -21,56 +28,6 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN ShapeFromShadingAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 8;
|
|
||||||
vertexSubsampling = 1;
|
|
||||||
chooseColour = 5;
|
|
||||||
multiplier = 3.0;
|
|
||||||
|
|
||||||
ofSetLineWidth(5.0f);
|
|
||||||
glPointSize(5.0f);
|
|
||||||
|
|
||||||
//blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
//blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
//blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
///setup light
|
|
||||||
ofEnableLighting();
|
|
||||||
GLfloat light_ambient[] = {0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
|
||||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT0);
|
|
||||||
|
|
||||||
GLfloat light_ambient1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_diffuse1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_specular1[] = { 0.5, 0.5, 0.5, 0.5 };
|
|
||||||
GLfloat light_position1[] = { -1.0, 1.0, 1.0, 0.0 };
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
glEnable(GL_LIGHT1);
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shapefromshading", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_shapefromshading", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME ShapeFromShadingAnalysis " << acq_run_time << endl;
|
||||||
@@ -97,50 +54,21 @@ void ShapeFromShadingAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
|
||||||
image4.clear();
|
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
image1.setUseTexture(false);
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image2.setUseTexture(true);
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
// cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
////---------
|
||||||
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
algo = RefractiveIndex::XML.getValue("config:algorithms:shapeshade:algo", algo_default);
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
scale = RefractiveIndex::XML.getValue("config:algorithms:shapeshade:scale", scale_default);
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:shapeshade:draw_style", draw_style_default);
|
||||||
cvColorImage1.clear();
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:shapeshade:line_width", line_width_default);
|
||||||
cvGrayImage1.clear();
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:shapeshade:point_size", point_size_default);
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
|
||||||
cvGrayImage2.clear();
|
|
||||||
cvGrayDiff2.clear();
|
|
||||||
|
|
||||||
cvConvertorImage.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvConvertorImage.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,207 +124,46 @@ void ShapeFromShadingAnalysis::acquire()
|
|||||||
|
|
||||||
void ShapeFromShadingAnalysis::synthesise()
|
void ShapeFromShadingAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
// cout << "ShapeFromShadingAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
/*
|
||||||
|
|
||||||
// cout << "ShapeFromShadingAnalysis::synthesis FOR LOOP...\n";
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
_RUN_DONE = false;
|
||||||
|
|
||||||
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShapeFromShadingAnalysis::displayresults()
|
||||||
|
{
|
||||||
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||||
|
|
||||||
|
while(!_image_shown){
|
||||||
|
Thread::sleep(2);
|
||||||
|
//cout << "!_image_shown" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
// cout << "LOADED image1!!!" << endl;
|
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
if(_saved_filenames_analysis[i].find("QUAD1")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameQuad = "QUAD1";
|
|
||||||
cout<<"FOUND QUAD1"<<endl;
|
|
||||||
} else if (_saved_filenames_analysis[i].find("QUAD2")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameQuad = "QUAD2";
|
|
||||||
cout<<"FOUND QUAD2"<<endl;
|
|
||||||
} else if(_saved_filenames_analysis[i].find("QUAD3")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameQuad = "QUAD3";
|
|
||||||
cout<<"FOUND QUAD3"<<endl;
|
|
||||||
} else if(_saved_filenames_analysis[i].find("QUAD4")<_saved_filenames_analysis[i].length())
|
|
||||||
{
|
|
||||||
fileNameQuad = "QUAD4";
|
|
||||||
cout<<"FOUND QUAD4"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayDiff1.absDiff(cvGrayImage2, cvGrayImage1);
|
|
||||||
//cvGrayDiff1.erode();
|
|
||||||
|
|
||||||
cvGrayImage1.dilate();
|
|
||||||
cvGrayImage1.blur(5);
|
|
||||||
cvGrayImage1.contrastStretch();
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
if(fileNameQuad=="QUAD1")
|
|
||||||
{
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD2")
|
|
||||||
{
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD3")
|
|
||||||
{
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD4") {
|
|
||||||
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_ShapeFromShadingAnalysis_"+fileNameQuad+"_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(3);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShapeFromShadingAnalysis::displayresults()
|
|
||||||
{
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
|
||||||
|
|
||||||
while(!_image_shown){
|
|
||||||
Thread::sleep(2);
|
|
||||||
//cout << "!_image_shown" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -408,48 +175,6 @@ void ShapeFromShadingAnalysis::displayresults()
|
|||||||
void ShapeFromShadingAnalysis::draw()
|
void ShapeFromShadingAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
//rotate light around origin ofviewspace
|
|
||||||
float xx=cos(ofGetElapsedTimef()*0.4)*150;
|
|
||||||
float yy=sin(ofGetElapsedTimef()*0.4)*150;
|
|
||||||
float zz=0;
|
|
||||||
|
|
||||||
if(fileNameQuad=="QUAD1")
|
|
||||||
{
|
|
||||||
|
|
||||||
GLfloat light_position[] = { 1000, 1000, 20, 0.0 };
|
|
||||||
GLfloat light_position1[] = { 1000, 1000, 20, 0.0 };
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD2")
|
|
||||||
{
|
|
||||||
|
|
||||||
GLfloat light_position[] = { 1000, -1000, 20, 0.0 };
|
|
||||||
GLfloat light_position1[] = { 1000, -1000, 20, 0.0 };
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD3")
|
|
||||||
{
|
|
||||||
|
|
||||||
GLfloat light_position[] = {-1000, 1000, 20, 0.0 };
|
|
||||||
GLfloat light_position1[] = { -1000, 1000, 20, 0.0 };
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
|
|
||||||
} else if(fileNameQuad=="QUAD4")
|
|
||||||
{
|
|
||||||
GLfloat light_position[] = { -1000, -1000, 20, 0.0 };
|
|
||||||
GLfloat light_position1[] = { -1000, -1000, 20, 0.0 };
|
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -752,8 +477,6 @@ void ShapeFromShadingAnalysis::draw()
|
|||||||
|
|
||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
// cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -762,23 +485,50 @@ void ShapeFromShadingAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
glPointSize(point_size);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
// cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -798,412 +548,3 @@ void ShapeFromShadingAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ShapeFromShadingAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> ShapeFromShadingAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
|
|
||||||
ofColor imageColor2 = imagePixels1.getColor(x+1, y+1);
|
|
||||||
|
|
||||||
ofColor imageColor3 = imagePixels1.getColor(x+2, y+2);
|
|
||||||
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getBrightness()+ofRandom(-50,50));
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
string quad;
|
string quad;
|
||||||
string fileNameQuad;
|
|
||||||
|
|
||||||
bool _RUN_DONE;
|
bool _RUN_DONE;
|
||||||
float _flip, _level;
|
float _flip, _level;
|
||||||
int _animation_cnt1;
|
int _animation_cnt1;
|
||||||
@@ -57,46 +55,14 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
int algo;
|
||||||
ofxCvColorImage cvColorImage2;
|
int scale;
|
||||||
ofxCvColorImage cvColorImage3;
|
int draw_style;
|
||||||
ofxCvColorImage cvColorImage4;
|
float line_width;
|
||||||
ofxCvColorImage cvColorImage5;
|
float point_size;
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//this is the temporary container to allow us to convert and save out greyscale images
|
|
||||||
ofxCvColorImage cvConvertorImage;
|
|
||||||
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
};
|
};
|
||||||
|
|||||||
+69
-655
@@ -13,6 +13,12 @@ using Poco::Thread;
|
|||||||
#define NUMBER_RUNS 1
|
#define NUMBER_RUNS 1
|
||||||
#define ACQUIRE_TIME 30
|
#define ACQUIRE_TIME 30
|
||||||
|
|
||||||
|
const int algo_default = 1;
|
||||||
|
const int scale_default = 500;
|
||||||
|
const int draw_style_default = 3;
|
||||||
|
const int line_width_default = 0.5f;
|
||||||
|
const float point_size_default = 0.5f;
|
||||||
|
|
||||||
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
void StrobeAnalysis::setup(int camWidth, int camHeight)
|
||||||
{
|
{
|
||||||
AbstractAnalysis::setup(camWidth, camHeight);
|
AbstractAnalysis::setup(camWidth, camHeight);
|
||||||
@@ -21,28 +27,6 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
cout << "NUM_RUN StrobeAnalysis " << NUM_RUN << endl;
|
||||||
//NUM_RUN = 5;
|
//NUM_RUN = 5;
|
||||||
|
|
||||||
//flag for main sketch
|
|
||||||
meshIsComplete=false;
|
|
||||||
_gotFirstImage=false;
|
|
||||||
_mesh_size_multiplier = 8;
|
|
||||||
vertexSubsampling = 3;
|
|
||||||
chooseColour = 2;
|
|
||||||
multiplier = 4.0;
|
|
||||||
|
|
||||||
//blendMode = OF_BLENDMODE_ADD;
|
|
||||||
//blendMode = OF_BLENDMODE_MULTIPLY;
|
|
||||||
blendMode = OF_BLENDMODE_SUBTRACT;
|
|
||||||
//blendMode = OF_BLENDMODE_ALPHA;
|
|
||||||
//blendMode = OF_BLENDMODE_SCREEN;
|
|
||||||
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLES;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_TRIANGLE_FAN;
|
|
||||||
meshMode = OF_PRIMITIVE_LINES;
|
|
||||||
//meshMode = OF_PRIMITIVE_LINE_STRIP;
|
|
||||||
//meshMode = OF_PRIMITIVE_POINTS;
|
|
||||||
|
|
||||||
|
|
||||||
int acq_run_time; // 10 seconds of acquiring per run
|
int acq_run_time; // 10 seconds of acquiring per run
|
||||||
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_strobe", ACQUIRE_TIME);
|
acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_strobe", ACQUIRE_TIME);
|
||||||
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
|
cout << "ACQUIRE_TIME StrobeAnalysis " << acq_run_time << endl;
|
||||||
@@ -70,47 +54,24 @@ void StrobeAnalysis::setup(int camWidth, int camHeight)
|
|||||||
|
|
||||||
image1.clear();
|
image1.clear();
|
||||||
image2.clear();
|
image2.clear();
|
||||||
image3.clear();
|
image1.clear();
|
||||||
image4.clear();
|
image2.clear();
|
||||||
image5.clear();
|
|
||||||
|
|
||||||
// images use for drawing the synthesized files to the screen ///
|
// images use for drawing the synthesized files to the screen ///
|
||||||
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
image1.setUseTexture(false); // the non texture image that is needed to first load the image
|
||||||
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
image2.setUseTexture(true); // the image that needs to get written to the screen which takes the content of image1
|
||||||
|
|
||||||
// images used for re-loading and saving out the synthesized files ///
|
|
||||||
image3.setUseTexture(false);
|
|
||||||
image4.setUseTexture(false);
|
|
||||||
image5.setUseTexture(false);
|
|
||||||
|
|
||||||
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
image2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
||||||
image3.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image4.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
image5.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h, OF_IMAGE_COLOR);
|
|
||||||
|
|
||||||
// cout << "RefractiveIndex::_vid_w " << RefractiveIndex::_vid_w << endl;
|
|
||||||
// cout << "RefractiveIndex::_vid_h " << RefractiveIndex::_vid_h << endl;
|
|
||||||
|
|
||||||
// clear() apparently fixes the "OF_WARNING: in allocate, reallocating a ofxCvImage"
|
////---------
|
||||||
// that we're getting in OSX/Windows and is maybe crashing Windows
|
|
||||||
// http://forum.openframeworks.cc/index.php?topic=1867.0
|
|
||||||
cvColorImage1.clear();
|
|
||||||
cvGrayImage1.clear();
|
|
||||||
cvGrayDiff1.clear();
|
|
||||||
|
|
||||||
cvColorImage2.clear();
|
|
||||||
cvGrayImage2.clear();
|
|
||||||
cvGrayDiff2.clear();
|
|
||||||
|
|
||||||
cvColorImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff1.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
cvColorImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayImage2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
cvGrayDiff2.allocate(RefractiveIndex::_vid_w,RefractiveIndex::_vid_h);
|
|
||||||
|
|
||||||
|
algo = RefractiveIndex::XML.getValue("config:algorithms:strobe:algo", algo_default);
|
||||||
|
scale = RefractiveIndex::XML.getValue("config:algorithms:strobe:scale", scale_default);
|
||||||
|
draw_style = RefractiveIndex::XML.getValue("config:algorithms:strobe:draw_style", draw_style_default);
|
||||||
|
line_width = RefractiveIndex::XML.getValue("config:algorithms:strobe:line_width", line_width_default);
|
||||||
|
point_size = RefractiveIndex::XML.getValue("config:algorithms:strobe:point_size", point_size_default);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,190 +108,45 @@ void StrobeAnalysis::acquire()
|
|||||||
|
|
||||||
void StrobeAnalysis::synthesise()
|
void StrobeAnalysis::synthesise()
|
||||||
{
|
{
|
||||||
// cout << "StrobeAnalysis::saving synthesis...\n";
|
// we don't need to synthesise
|
||||||
if(_state == STATE_STOP) return;
|
return;
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_analysis.size()-1;i++){
|
|
||||||
|
|
||||||
// cout << "StrobeAnalysis::synthesis FOR LOOP...\n";
|
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i]" << _saved_filenames_analysis[i] << endl;
|
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
|
||||||
|
|
||||||
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//couldn't load image
|
|
||||||
// cout << "didn't load image" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(image1.loadImage(_saved_filenames_analysis[i])){
|
|
||||||
//cout << "LOADED image1!!!" << endl;
|
|
||||||
if(image5.loadImage(_saved_filenames_analysis[i+1])){
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
|
|
||||||
cvColorImage1.setFromPixels(image1.getPixels(), image1.width, image1.height);
|
|
||||||
cvColorImage2.setFromPixels(image5.getPixels(), image5.width, image5.height);
|
|
||||||
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
//cvColorImage1.erode();
|
|
||||||
//cvColorImage1.dilate();
|
|
||||||
|
|
||||||
cvColorImage1.blur(1);
|
|
||||||
cvColorImage2.blur(1);
|
|
||||||
|
|
||||||
//cvXorS( cvColorImage1.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
//cvXorS( cvColorImage2.getCvImage(), cvScalarAll(150), cvColorImage1.getCvImage(), 0 );
|
|
||||||
|
|
||||||
cvColorImage1.convertToGrayscalePlanarImage(cvGrayImage1, 1);
|
|
||||||
cvColorImage2.convertToGrayscalePlanarImage(cvGrayImage2, 1);
|
|
||||||
|
|
||||||
//cvGrayImage1.convertToRange(0.0, 255.0);
|
|
||||||
//cvGrayImage2.convertToRange(0.0, 255.0);
|
|
||||||
|
|
||||||
//cvGrayImage1.adaptiveThreshold( 200, 0);
|
|
||||||
//cvGrayImage2.adaptiveThreshold( 200, 0);
|
|
||||||
|
|
||||||
//cvGrayImage1.contrastStretch();
|
|
||||||
//cvGrayImage2.contrastStretch();
|
|
||||||
|
|
||||||
cvGrayDiff1.absDiff(cvGrayImage1, cvGrayImage2);
|
|
||||||
|
|
||||||
cvGrayDiff1.brightnessContrast(1.0,0.5);
|
|
||||||
|
|
||||||
//cvGrayImage1.brightnessContrast(1.0,0.5);
|
|
||||||
//cvGrayImage2.brightnessContrast(1.0,0.5);
|
|
||||||
|
|
||||||
cvColorImage1.setFromGrayscalePlanarImages(cvGrayImage1, cvGrayImage1, cvGrayImage1);
|
|
||||||
//cvColorImage2.setFromGrayscalePlanarImages(cvGrayImage2, cvGrayImage2, cvGrayImage2);
|
|
||||||
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), 1, 1);
|
|
||||||
//cvPyrMeanShiftFiltering(cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), 1, 1);
|
|
||||||
|
|
||||||
//cvFloatImage1 = cvColorImage1;
|
|
||||||
//cvGrayImage1 = cvColorImage1;
|
|
||||||
|
|
||||||
|
|
||||||
//cvSmooth( cvColorImage1.getCvImage(), cvColorImage1.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
//cvSmooth( cvColorImage2.getCvImage(), cvColorImage2.getCvImage(), CV_GAUSSIAN, 5, 5);
|
|
||||||
|
|
||||||
//cvCanny(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 100, 100, 3);
|
|
||||||
//cvLaplace(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0);
|
|
||||||
|
|
||||||
//cvGrayImage1 = cvCreateImage(cvSize(image1.width, image1.height),IPL_DEPTH_16S,1);
|
|
||||||
//cvSobel(cvGrayImage1.getCvImage(), cvGrayImage1.getCvImage(), 0, 1, 3);
|
|
||||||
|
|
||||||
// convert the CV image
|
|
||||||
image1.setFromPixels(cvColorImage1.getPixelsRef());
|
|
||||||
image5.setFromPixels(cvColorImage2.getPixelsRef());
|
|
||||||
|
|
||||||
///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES //////////////////////////
|
|
||||||
if(!_gotFirstImage){
|
|
||||||
cout<<"background image is"<< _saved_filenames_analysis[i]<<endl;
|
|
||||||
_background=image1;
|
|
||||||
_gotFirstImage=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//subtract background begin///////////////
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
ofPixels imagePixels2 = image5.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = _background.getPixelsRef();
|
|
||||||
|
|
||||||
//DIFFERENCING SUBSEQUENT IMAGES
|
|
||||||
/*
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-imagePixels2[i]>0){
|
|
||||||
imagePixels1[i]-=imagePixels2[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//DIFFERENCING THE BACKGROUND
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
//unsigned char val=imagePixels1[i];
|
|
||||||
// cout<<(int)backgroundPixels[i]<< " thesePixels[i] "<<(int)imagePixels1[i]<<endl;
|
|
||||||
if(imagePixels1[i]-backgroundPixels[i]>0){
|
|
||||||
imagePixels1[i]-=backgroundPixels[i];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
imagePixels1[i]=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the images with their new background subtracted selves
|
|
||||||
image1.setFromPixels(imagePixels1);
|
|
||||||
|
|
||||||
//flag the main app that we aren't read yet
|
|
||||||
meshIsComplete=false;
|
|
||||||
|
|
||||||
//make a mesh - this mesh will be drawn in the main app
|
|
||||||
setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
//setMeshFromPixels(_returnDepthsAtEachPixel(image1, image1, _background), image1, image1, aMesh);
|
|
||||||
|
|
||||||
/////////////////////////////////// SAVE TO DISK IN THE SYNTHESIS FOLDER ////////////////////////////////
|
|
||||||
//string file_name;
|
|
||||||
|
|
||||||
//with jpgs this was refusing to save out
|
|
||||||
meshFileName = _whole_file_path_synthesis+"/"+ofToString(_synth_save_cnt, 2)+"_StrobeAnalysis_"+ofToString(_run_cnt,2)+".png";
|
|
||||||
_saved_filenames_synthesis.push_back(meshFileName);
|
|
||||||
|
|
||||||
//file_name = ofToString(_synth_save_cnt, 2)+"_ColorMultiAnalysis_"+ofToString(_run_cnt,2)+".jpg";
|
|
||||||
|
|
||||||
//flag that we are finished
|
|
||||||
meshIsComplete=true;
|
|
||||||
_synth_save_cnt++;
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cout<<"couldn't load image from "<<_saved_filenames_analysis[i]<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TOM'S fix of why the last file gets overwritten again and again - but seems to prevent the files being written to the screen.
|
|
||||||
/*
|
/*
|
||||||
_RUN_DONE = true;
|
|
||||||
|
//cout << "IResponseAnalysis::saving synthesis...\n";
|
||||||
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
|
_RUN_DONE = false;
|
||||||
|
|
||||||
|
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
||||||
|
while(!_RUN_DONE && _state != STATE_STOP)
|
||||||
|
Thread::sleep(3);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
meshIsComplete=false;
|
|
||||||
_synth_save_cnt=0;
|
|
||||||
|
|
||||||
// _saved_filenames_synthesis has processed all the files in the analysis images folder
|
|
||||||
|
|
||||||
while(!_RUN_DONE && _state != STATE_STOP)
|
|
||||||
Thread::sleep(10);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrobeAnalysis::displayresults()
|
void StrobeAnalysis::displayresults()
|
||||||
{
|
{
|
||||||
|
|
||||||
for(float i=1;i<_saved_filenames_synthesis.size();i++){
|
for(float i=1;i<_saved_filenames_analysis.size();i++){
|
||||||
|
|
||||||
if(_state == STATE_STOP) return;
|
if(_state == STATE_STOP) return;
|
||||||
|
|
||||||
// cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
//cout << "_saved_filenames_analysis[i] - " << _saved_filenames_synthesis[i] << endl;
|
||||||
|
|
||||||
while(!_image_shown){
|
while(!_image_shown){
|
||||||
Thread::sleep(2);
|
Thread::sleep(2);
|
||||||
//cout << "!_image_shown" << endl;
|
//cout << "!_image_shown" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!image3.loadImage(_saved_filenames_synthesis[i])){
|
_show_image = false;
|
||||||
|
|
||||||
|
|
||||||
|
if(!image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
//couldn't load image
|
//couldn't load image
|
||||||
// cout << "didn't load image" << endl;
|
cout << "didn't load image" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image3.loadImage(_saved_filenames_synthesis[i])){
|
if(image1.loadImage(_saved_filenames_analysis[i])){
|
||||||
image3.loadImage(_saved_filenames_synthesis[i]);
|
|
||||||
//cout << "_show_image = true;" << endl;
|
//cout << "_show_image = true;" << endl;
|
||||||
_show_image = true;
|
_show_image = true;
|
||||||
_image_shown = false;
|
_image_shown = false;
|
||||||
@@ -344,27 +160,6 @@ void StrobeAnalysis::displayresults()
|
|||||||
void StrobeAnalysis::draw()
|
void StrobeAnalysis::draw()
|
||||||
{
|
{
|
||||||
|
|
||||||
ofEnableSmoothing();
|
|
||||||
|
|
||||||
ofEnableLighting();
|
|
||||||
ofEnableSeparateSpecularLight();
|
|
||||||
light.setPointLight();
|
|
||||||
|
|
||||||
light.enable();
|
|
||||||
lightStatic.enable();
|
|
||||||
|
|
||||||
light.setPosition(ofGetWidth()/2,ofGetHeight()/2,5);
|
|
||||||
|
|
||||||
lightStatic.setPosition(ofGetWidth()/2,ofGetHeight()/2,-1);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
ofSetLineWidth(1.0f);
|
|
||||||
glPointSize(5.0f);
|
|
||||||
|
|
||||||
ofEnableBlendMode(blendMode);
|
|
||||||
|
|
||||||
|
|
||||||
switch (_state) {
|
switch (_state) {
|
||||||
case STATE_ACQUIRING:
|
case STATE_ACQUIRING:
|
||||||
{
|
{
|
||||||
@@ -383,6 +178,7 @@ void StrobeAnalysis::draw()
|
|||||||
ofRect(0, 0, ofGetWidth(), ofGetHeight());
|
ofRect(0, 0, ofGetWidth(), ofGetHeight());
|
||||||
//cout << "FADE IN STROBE TIME " << endl;
|
//cout << "FADE IN STROBE TIME " << endl;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
|
if (_frame_cnt >= _fade_in_frames && _frame_cnt < (_frame_cnt_max-_fade_in_frames)){
|
||||||
@@ -414,7 +210,6 @@ void StrobeAnalysis::draw()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
ofDisableAlphaBlending();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//_state = STATE_SYNTHESISING;
|
//_state = STATE_SYNTHESISING;
|
||||||
_RUN_DONE = true;
|
_RUN_DONE = true;
|
||||||
@@ -511,8 +306,6 @@ void StrobeAnalysis::draw()
|
|||||||
case STATE_DISPLAY_RESULTS:
|
case STATE_DISPLAY_RESULTS:
|
||||||
{
|
{
|
||||||
|
|
||||||
// cout << "STATE_DISPLAY_RESULTS...\n" << endl;
|
|
||||||
|
|
||||||
if (_frame_cnt > 2)
|
if (_frame_cnt > 2)
|
||||||
{
|
{
|
||||||
_image_shown = true;
|
_image_shown = true;
|
||||||
@@ -521,21 +314,47 @@ void StrobeAnalysis::draw()
|
|||||||
|
|
||||||
_frame_cnt++;
|
_frame_cnt++;
|
||||||
|
|
||||||
|
ofEnableAlphaBlending();
|
||||||
|
glShadeModel(GL_SMOOTH);
|
||||||
|
glLineWidth(line_width);
|
||||||
|
glPointSize(point_size);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.begin();
|
||||||
|
|
||||||
|
ofTranslate(tx, ty, tz);
|
||||||
|
ofRotateX(rx); ofRotateY(ry); ofRotateZ(rz);
|
||||||
|
glScalef(1.5, 1, 1);
|
||||||
|
|
||||||
if (_show_image)
|
if (_show_image)
|
||||||
{
|
image2.setFromPixels(image1.getPixels(), image1.width, image1.height, OF_IMAGE_COLOR);
|
||||||
// cout << "_show_image...\n" << endl;
|
|
||||||
|
|
||||||
ofEnableAlphaBlending();
|
image2.bind();
|
||||||
|
|
||||||
ofSetColor(255, 255, 255);
|
RefractiveIndex::_shader.begin();
|
||||||
image2.setFromPixels(image3.getPixels(),image3.width,image3.height, OF_IMAGE_COLOR);
|
|
||||||
image2.draw(0,0, ofGetWidth(), ofGetHeight());
|
|
||||||
|
|
||||||
ofDisableAlphaBlending();
|
RefractiveIndex::_shader.setUniform1i("algo", algo);
|
||||||
|
RefractiveIndex::_shader.setUniform1f("scale", scale);
|
||||||
|
RefractiveIndex::_shader.setUniform1i("tex0", 0);
|
||||||
|
|
||||||
|
switch (draw_style) {
|
||||||
|
case VERTS:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawVertices();
|
||||||
|
break;
|
||||||
|
case WIRE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawWireframe();
|
||||||
|
break;
|
||||||
|
case FACE:
|
||||||
|
RefractiveIndex::_mesh_vbo.drawFaces();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display results of the synthesis
|
RefractiveIndex::_shader.end();
|
||||||
_RUN_DONE = true;
|
|
||||||
|
image2.unbind();
|
||||||
|
|
||||||
|
//RefractiveIndex::cam.end();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@@ -557,408 +376,3 @@ void StrobeAnalysis::save_cb(Timer& timer)
|
|||||||
|
|
||||||
saveImageAnalysis(file_name);
|
saveImageAnalysis(file_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StrobeAnalysis::setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh){
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
//get rid of all previous vectors and colours
|
|
||||||
mesh.clear();
|
|
||||||
mesh.setMode(meshMode);
|
|
||||||
|
|
||||||
ofColor meshColour=ofColor(255,255,255);
|
|
||||||
|
|
||||||
//the average z position of the matrix - used later to centre the mesh on the z axis when drawing
|
|
||||||
float zPlaneAverage=0;
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
zPlaneAverage+=sPixels[i];
|
|
||||||
}
|
|
||||||
if (sPixels.size()!=0) {
|
|
||||||
zPlaneAverage/=sPixels.size();
|
|
||||||
//cout<<zPlaneAverage<<" zPlaneAverage "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
cout<<"DEPTH FLOAT ARRAY IS EMPTY";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==1){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y+1));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x, y));
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImage.getColor(x+1, y) );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==2){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==3){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*(y+1),- sPixels[ (currentSecondImage.getWidth()*(y+1))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*(y+1),- sPixels[(currentSecondImage.getWidth()*(y+1))+x+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*x,_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor);
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==4){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
int randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*((y+randomJitter)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+randomJitter),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageColor.getBrightness());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x+randomJitter)+1),_mesh_size_multiplier*(y+randomJitter),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) +1 ]));
|
|
||||||
|
|
||||||
ofSeedRandom();
|
|
||||||
|
|
||||||
currentSecondImageColor.r = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.g = ofRandom(0,255);
|
|
||||||
currentSecondImageColor.b = ofRandom(0,255);
|
|
||||||
|
|
||||||
randomJitter = ofRandom(0,5);
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(chooseColour==5){
|
|
||||||
|
|
||||||
for(int i=0;i<sPixels.size();i++){
|
|
||||||
|
|
||||||
int randomJitter2 = 0;
|
|
||||||
int randomJitter = 0;
|
|
||||||
|
|
||||||
ofColor currentSecondImageColor;
|
|
||||||
ofColor currentSecondImageBW;
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*((y)+1),- sPixels[ (currentSecondImage.getWidth()*(y+randomJitter+1))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor(currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1 ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y+1);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*((y)+1),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)+1))+(x+randomJitter)+1] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp());
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter) ] ));
|
|
||||||
|
|
||||||
currentSecondImageColor = currentSecondImage.getColor(x+1, y);
|
|
||||||
currentSecondImageBW.r = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.g = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
currentSecondImageBW.b = currentSecondImageColor.getBrightness()+randomJitter2;
|
|
||||||
|
|
||||||
mesh.addColor( currentSecondImageBW.clamp() );
|
|
||||||
mesh.addVertex(ofVec3f(_mesh_size_multiplier*((x)+1),_mesh_size_multiplier*(y),- sPixels[(currentSecondImage.getWidth()*((y+randomJitter)))+(x+randomJitter)+1 ]));
|
|
||||||
|
|
||||||
x=x+vertexSubsampling;
|
|
||||||
if(x>=currentSecondImage.getWidth()-1){
|
|
||||||
x=0;
|
|
||||||
y=y+vertexSubsampling;
|
|
||||||
//something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector?
|
|
||||||
if(y>=currentSecondImage.getHeight()-1){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
vector<float> StrobeAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){
|
|
||||||
|
|
||||||
ofPixels imagePixels1 = image1.getPixelsRef();
|
|
||||||
//ofPixels imagePixels2 = image2.getPixelsRef();
|
|
||||||
ofPixels backgroundPixels = backgroundImag.getPixelsRef();
|
|
||||||
vector<float> differences;
|
|
||||||
|
|
||||||
ofPixels difference;
|
|
||||||
|
|
||||||
//this unsigned char should be unnecessary - I would have thought - can't you just address the pixel locations in ofPixels directly?
|
|
||||||
unsigned char * thesePixels = new unsigned char[imagePixels1.getWidth()*imagePixels1.getHeight()*3];
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i++){
|
|
||||||
thesePixels[i]=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int x=0;
|
|
||||||
int y=0;
|
|
||||||
|
|
||||||
int chooseComparison=1;
|
|
||||||
|
|
||||||
//comparison here to find out how close each color is to pure RED / GREEN / BLUE
|
|
||||||
|
|
||||||
if(chooseComparison==1){
|
|
||||||
//for each pixel...
|
|
||||||
float _maxPossibleDistanceToCentre=ofDist(0,0,imagePixels1.getWidth()/2, imagePixels1.getHeight()/2);
|
|
||||||
|
|
||||||
for(int i=0;i<imagePixels1.size();i+=3){
|
|
||||||
|
|
||||||
ofColor imageColor1 = imagePixels1.getColor(x, y);
|
|
||||||
//ofColor colourImage2 = imagePixels2.getColor(x, y);
|
|
||||||
|
|
||||||
float _distanceToCentre=ofDist(imagePixels1.getWidth()/2, imagePixels1.getHeight()/2, x, y);
|
|
||||||
float _presumedBrightness=ofMap(sqrt(_maxPossibleDistanceToCentre)-sqrt(_distanceToCentre), 0, sqrt(_maxPossibleDistanceToCentre), 0, 255);
|
|
||||||
|
|
||||||
//int thisDiff=abs(imageColor1.getHue());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness);
|
|
||||||
|
|
||||||
int thisDiff=-abs(imageColor1.getBrightness());
|
|
||||||
//int thisDiff=abs(imageColor1.getLightness());
|
|
||||||
//int thisDiff=-abs(imageColor1.r);
|
|
||||||
|
|
||||||
//cout<<thisDiff<< " thisDiff "<<endl;
|
|
||||||
|
|
||||||
//red hue: 0
|
|
||||||
//green hue: 120
|
|
||||||
//blue hue: 240
|
|
||||||
|
|
||||||
differences.push_back(multiplier * thisDiff);
|
|
||||||
|
|
||||||
thesePixels[i]=thisDiff;
|
|
||||||
thesePixels[i+1]=thisDiff;
|
|
||||||
thesePixels[i+2]=thisDiff;
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if(x>=imagePixels1.getWidth()){
|
|
||||||
x=0;
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//difference.setFromPixels(thesePixels,imagePixels1.getWidth(),imagePixels1.getHeight(), 3);
|
|
||||||
return differences;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+6
-36
@@ -41,44 +41,14 @@ protected:
|
|||||||
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
float c, _frame_cnt, _frame_cnt_max, _anim_cnt_max;
|
||||||
|
|
||||||
bool _show_image, _image_shown;
|
bool _show_image, _image_shown;
|
||||||
|
|
||||||
ofImage image1;
|
ofImage image1;
|
||||||
ofImage image2;
|
ofImage image2;
|
||||||
ofImage image3;
|
|
||||||
ofImage image4;
|
|
||||||
ofImage image5;
|
|
||||||
ofImage image6;
|
|
||||||
|
|
||||||
ofxCvColorImage cvColorImage1;
|
|
||||||
ofxCvColorImage cvColorImage2;
|
|
||||||
ofxCvColorImage cvColorImage3;
|
|
||||||
ofxCvColorImage cvColorImage4;
|
|
||||||
ofxCvColorImage cvColorImage5;
|
|
||||||
ofxCvColorImage cvColorImage6;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff1;
|
|
||||||
ofxCvGrayscaleImage cvGrayDiff2;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage cvGrayImage1;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage2;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage3;
|
|
||||||
ofxCvGrayscaleImage cvGrayImage4;
|
|
||||||
|
|
||||||
ofxCvContourFinder cvContourFinder1;
|
|
||||||
|
|
||||||
//mesh making function
|
|
||||||
void setMeshFromPixels(vector<float> sPixels, ofImage currentFirstImage, ofImage currentSecondImage, ofMesh & mesh);
|
|
||||||
|
|
||||||
//depth map function
|
|
||||||
vector<float> _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage);
|
|
||||||
|
|
||||||
int vertexSubsampling;
|
|
||||||
int chooseColour;
|
|
||||||
ofPrimitiveMode meshMode;
|
|
||||||
ofBlendMode blendMode;
|
|
||||||
float multiplier;
|
|
||||||
|
|
||||||
bool _gotFirstImage;
|
|
||||||
ofImage _background;
|
|
||||||
|
|
||||||
|
int algo;
|
||||||
|
int scale;
|
||||||
|
int draw_style;
|
||||||
|
float line_width;
|
||||||
|
float point_size;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user