~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina5/tina-libs/tina/vision/visMatch_cstereo.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  *
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/vision/visMatch_cstereo.c,v $
 23  * Date    :  $Date: 2005/02/07 23:27:41 $
 24  * Version :  $Revision: 1.4 $
 25  * CVS Id  :  $Id: visMatch_cstereo.c,v 1.4 2005/02/07 23:27:41 paul Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  *
 31  *********
 32 */
 33 
 34 #include "visMatch_cstereo.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <tina/sys/sysDef.h>
 42 #include <tina/sys/sysPro.h>
 43 #include <tina/math/mathDef.h>
 44 #include <tina/geometry/geomDef.h>
 45 #include <tina/geometry/geomPro.h>
 46 #include <tina/vision/vis_MatchPro.h>
 47 
 48 static double disp, lowd, upd, width, correlate, uniqueness;
 49 static double asymetry = 0.85, range = 3.0;
 50 static Imrect *im_left, *im_right;      /* Defined in
 51                                          * corner/t_mat_cnr.c */
 52 
 53 void    stereo_corner_match(Imrect *im_left_new, Imrect *im_right_new,
 54        Imrect *left_er,Imrect *right_er,
 55        double new_disp, double new_lowd, double new_upd,
 56        double new_width, double new_corr, double new_unique, double new_asym)
 57 {
 58     Rindex *fxl;
 59     Rindex *fxr;
 60     Imregion left_search_func(Edgel * edgel);
 61     Imregion right_search_func(Edgel * edgel);
 62     Rindex *er_set_findex();
 63     int     type = MLIST;
 64     Vec2   *rectpos(Edgel * edgel);
 65 
 66     if (left_er == NULL || right_er == NULL)
 67     {
 68         error("no edge structure", non_fatal);
 69         return;
 70     }
 71     im_left = im_left_new;
 72     im_right = im_right_new;
 73 
 74     if (im_left == NULL || im_right == NULL)
 75     {
 76         error("no images", non_fatal);
 77         return;
 78     }
 79     if ((fxl = prop_get(left_er->props, ER_FINDEX)) == NULL)
 80         if ((fxl = er_set_findex(left_er, ER_FINDEX, rectpos)) == NULL)
 81             return;
 82     if ((fxr = prop_get(right_er->props, ER_FINDEX)) == NULL)
 83         if ((fxr = er_set_findex(right_er, ER_FINDEX, rectpos)) == NULL)
 84             return;
 85 
 86     disp = new_disp;
 87     lowd = new_lowd * left_er->width;
 88     upd = new_upd * left_er->width;
 89     width = new_width;
 90     correlate = new_corr;
 91     uniqueness = new_unique;
 92     asymetry = new_asym;
 93 
 94     rm_corner_matches(fxl, &type);
 95     get_corner_matches(fxl, fxr, RECTPOS, left_search_func, stereo_left_match);
 96     rm_corner_matches(fxr, &type);
 97     get_corner_matches(fxr, fxl, RECTPOS, right_search_func, stereo_right_match);
 98     set_stereo_corner_matches(fxl);
 99 }
100 
101 Vec2   *rectpos(Edgel * edgel)
102 {
103     return ((Vec2 *) prop_get(edgel->props, RECTPOS));
104 }
105 
106 void   *stereo_left_match(Edgel * edgell, Edgel * edgelr)
107 {
108     float   corr;
109 
110     corr = good_corner(edgell, edgelr, (float) range, (float) asymetry, im_left, im_right);
111 
112     if (corr > correlate - uniqueness)
113     {
114         Match  *match;
115         Match  *match_alloc();
116 
117         match = match_alloc(CORNER);
118         match->weight = corr;
119         match->to1 = (void *) edgell;
120         match->to2 = (void *) edgelr;
121         add_match_to_props(edgell, (void *) match, MLIST);
122     }
123     /* Return may be used in future */
124     return NULL;
125 }
126 
127 void   *stereo_right_match(Edgel * edgelr, Edgel * edgell)
128 {
129     float   corr;
130 
131     corr = good_corner(edgelr, edgell, (float) range, (float) asymetry, im_right, im_left);
132 
133     if (corr > correlate - uniqueness)
134     {
135         Match  *match;
136         Match  *match_alloc();
137 
138         match = match_alloc(CORNER);
139         match->weight = corr;
140         match->to1 = (void *) edgell;
141         match->to2 = (void *) edgelr;
142         add_match_to_props(edgelr, (void *) match, MLIST);
143     }
144     /* Return may be used in future */
145     return NULL;
146 }
147 
148 Imregion left_search_func(Edgel * edgel)
149 {
150     Imregion stereor = {Imregion_id};
151     Vec2   *rect;
152 
153     rect = (Vec2 *) prop_get(edgel->props, RECTPOS);
154     if (rect == NULL)
155         rect = &edgel->pos;
156 
157     stereor.lx = (int)floor(rect->el[0] + lowd + disp);
158     stereor.ux = (int)floor(rect->el[0] + upd + disp);
159     stereor.ly = (int)floor(rect->el[1] - width);
160     stereor.uy = (int)floor(rect->el[1] + width);
161     return (stereor);
162 }
163 
164 Imregion right_search_func(Edgel * edgel)
165 {
166     Imregion stereor = {Imregion_id};
167     Vec2   *rect;
168 
169     rect = (Vec2 *) prop_get(edgel->props, RECTPOS);
170     if (rect == NULL)
171         rect = &edgel->pos;
172 
173     stereor.lx = (int)floor(rect->el[0] - upd - disp);
174     stereor.ux = (int)floor(rect->el[0] - lowd - disp);
175     stereor.ly = (int)floor(rect->el[1] - width);
176     stereor.uy = (int)floor(rect->el[1] + width);
177     return (stereor);
178 }
179 
180 void    set_stereo_corner_matches(Rindex * fxl)
181 {
182     void   *data = NULL;
183 
184     apply_func_to_windex(fxl, (void *(*) ()) set_stereo_corner_match, data);
185 }
186 
187 void    rm_stereo_corner_matches(Rindex * fx)
188 {
189     apply_func_to_windex(fx, (void *(*) ()) rm_match_from_props, (void *) MLIST);
190 }
191 
192 /* ARGSUSED quieten lint */
193 /* BUGFIX: JB 22/11/93 was void   *set_stereo_corner_match(Edgel *
194  * ledge, void *data) */
195 void    set_stereo_corner_match(Edgel * ledge, void *data /* unused */ )
196 {
197     Edgel  *redge;
198     List   *left_matches;
199     List   *right_matches;
200     Match  *best_left_match;
201     Match  *next_best_left;
202     Match  *best_right_match;
203     Match  *next_best_right;
204 
205     if ((left_matches = (List *) prop_get(ledge->props, MLIST)) == NULL)
206         return;
207     if ((best_left_match = (Match *) left_matches->to) == NULL)
208         return;
209 
210     if ((redge = (Edgel *) best_left_match->to2) == NULL)
211         return;
212 
213     if ((right_matches = (List *) prop_get(redge->props, MLIST)) == NULL)
214         return;
215     if ((best_right_match = (Match *) right_matches->to) == NULL)
216         return;
217 
218     if (ledge == best_right_match->to1 && best_left_match->weight > correlate)
219     {
220         left_matches->type = FIXED_MATCH;
221         right_matches->type = FIXED_MATCH;
222         if (left_matches->next != NULL && (next_best_left = (Match *) left_matches->next->to) != NULL)
223         {
224             if ((best_left_match->weight - next_best_left->weight) < uniqueness)
225             {
226                 left_matches->type = GOOD_MATCH;
227                 right_matches->type = GOOD_MATCH;
228             }
229         }
230         if (right_matches->next != NULL && (next_best_right = (Match *) right_matches->next->to) != NULL)
231         {
232             if ((best_right_match->weight - next_best_right->weight) < uniqueness)
233             {
234                 left_matches->type = GOOD_MATCH;
235                 right_matches->type = GOOD_MATCH;
236             }
237         }
238     }
239 }
240 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.