예제 #1
0
        /**
         * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
         *
         * @param i_x_coord
         * @param i_y_coord
         * @param i_vertex1_index
         * @param i_coord_num
         * @param i_area
         * @param o_vertex
         * 要素数はint[4]である事
         * @return
         */
        private bool getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
        {
            NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
            NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
            int end_of_coord      = i_vertex1_index + i_coord_num - 1;
            int sx   = i_x_coord[i_vertex1_index]; // sx = marker_info2->x_coord[0];
            int sy   = i_y_coord[i_vertex1_index]; // sy = marker_info2->y_coord[0];
            int dmax = 0;
            int v1   = i_vertex1_index;
            int d;

            for (int i = 1 + i_vertex1_index; i < end_of_coord; i++)
            {// for(i=1;i<marker_info2->coord_num-1;i++)
                // {
                d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
                if (d > dmax)
                {
                    dmax = d;
                    v1   = i;
                }
            }
            double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;

            o_vertex[0] = i_vertex1_index;

            if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh))
            { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
                // 0 ) {
                return(false);
            }
            if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh))
            {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
                // < 0) {
                return(false);
            }

            int v2;

            if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
            {// if(wvnum1 == 1 && wvnum2== 1) {
                o_vertex[1] = wv1.vertex[0];
                o_vertex[2] = v1;
                o_vertex[3] = wv2.vertex[0];
            }
            else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0)
            {// }else if( wvnum1 > 1 && wvnum2== 0) {
                //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
                v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;
                if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh))
                {
                    return(false);
                }
                if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh))
                {
                    return(false);
                }
                if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
                {
                    o_vertex[1] = wv1.vertex[0];
                    o_vertex[2] = wv2.vertex[0];
                    o_vertex[3] = v1;
                }
                else
                {
                    return(false);
                }
            }
            else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1)
            {
                //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
                v2 = (v1 + end_of_coord) / 2;

                if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh))
                {
                    return(false);
                }
                if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh))
                {
                    return(false);
                }
                if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
                {
                    o_vertex[1] = v1;
                    o_vertex[2] = wv1.vertex[0];
                    o_vertex[3] = wv2.vertex[0];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            o_vertex[4] = end_of_coord;
            return(true);
        }
예제 #2
0
        /**
         * 座標集合から、頂点候補になりそうな場所を4箇所探して、そのインデクス番号を返します。
         * @param i_coord
         * 輪郭を格納した配列です。
         * @param i_area
         * @param o_vertex
         * @return
         */
        public bool getVertexIndexes(NyARIntCoordinates i_coord, int i_area, int[] o_vertex)
        {
            NyARVertexCounter wv1    = this.__getSquareVertex_wv1;
            NyARVertexCounter wv2    = this.__getSquareVertex_wv2;
            int    i_coord_num       = i_coord.length;
            int    vertex1_index     = getFarPoint(i_coord.items, i_coord_num, 0);
            int    prev_vertex_index = (vertex1_index + i_coord_num) % i_coord_num;
            int    v1     = getFarPoint(i_coord.items, i_coord_num, vertex1_index);
            double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;

            o_vertex[0] = vertex1_index;

            if (!wv1.getVertex(i_coord.items, i_coord_num, vertex1_index, v1, thresh))
            {
                return(false);
            }
            if (!wv2.getVertex(i_coord.items, i_coord_num, v1, prev_vertex_index, thresh))
            {
                return(false);
            }

            int v2;

            if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
            {
                o_vertex[1] = wv1.vertex[0];
                o_vertex[2] = v1;
                o_vertex[3] = wv2.vertex[0];
            }
            else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0)
            {
                //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
                if (v1 >= vertex1_index)
                {
                    v2 = (v1 - vertex1_index) / 2 + vertex1_index;
                }
                else
                {
                    v2 = ((v1 + i_coord_num - vertex1_index) / 2 + vertex1_index) % i_coord_num;
                }
                if (!wv1.getVertex(i_coord.items, i_coord_num, vertex1_index, v2, thresh))
                {
                    return(false);
                }
                if (!wv2.getVertex(i_coord.items, i_coord_num, v2, v1, thresh))
                {
                    return(false);
                }
                if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
                {
                    o_vertex[1] = wv1.vertex[0];
                    o_vertex[2] = wv2.vertex[0];
                    o_vertex[3] = v1;
                }
                else
                {
                    return(false);
                }
            }
            else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1)
            {
                //v2 = (v1+ end_of_coord)/2;
                if (v1 <= prev_vertex_index)
                {
                    v2 = (v1 + prev_vertex_index) / 2;
                }
                else
                {
                    v2 = ((v1 + i_coord_num + prev_vertex_index) / 2) % i_coord_num;
                }
                if (!wv1.getVertex(i_coord.items, i_coord_num, v1, v2, thresh))
                {
                    return(false);
                }
                if (!wv2.getVertex(i_coord.items, i_coord_num, v2, prev_vertex_index, thresh))
                {
                    return(false);
                }
                if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)
                {
                    o_vertex[1] = v1;
                    o_vertex[2] = wv1.vertex[0];
                    o_vertex[3] = wv2.vertex[0];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }