2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core2.rasteranalyzer;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.raster.*;
\r
35 import jp.nyatla.nyartoolkit.core.types.stack.*;
\r
36 import jp.nyatla.nyartoolkit.core.types.*;
\r
37 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
40 * QRコードの4頂点候補を探そうとするクラス。
\r
44 public class NyARRasterDetector_QrCodeEdge
\r
46 private NyARIntRectStack _result;
\r
48 public NyARRasterDetector_QrCodeEdge(int i_result_max)
\r
50 this._result = new NyARIntRectStack(i_result_max);
\r
54 public NyARIntRectStack geResult()
\r
56 return this._result;
\r
59 private boolean check_w1(int i_w1)
\r
63 private boolean check_b1(int i_b1)
\r
67 private boolean check_w2(int i_b1,int i_w2)
\r
69 int v=i_w2*100/i_b1;
\r
70 return (30<=v && v<=170);
\r
72 private boolean check_b2(int i_b1,int i_b2)
\r
74 int v=i_b2*100/i_b1;
\r
76 return (200<=v && v<=400);
\r
78 private boolean check_w3(int i_w2,int i_w3)
\r
80 int v=i_w3*100/i_w2;
\r
81 return (50<=v && v<=150);
\r
83 private boolean check_b3(int i_b3,int i_b1)
\r
85 int v=i_b3*100/i_b1;
\r
86 return (50<=v && v<=150);
\r
88 public void analyzeRaster(INyARRaster i_input) throws NyARException
\r
90 INyARBufferReader buffer_reader=i_input.getBufferReader();
\r
91 assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8));
\r
94 this._result.clear();
\r
96 NyARIntSize size = i_input.getSize();
\r
98 int w1, b1, w2, b2, w3, b3;
\r
99 w1 = b1 = w2 = b2 = w3 = b3 = 0;
\r
102 int[] raster_buf=(int[])buffer_reader.getBuffer();
\r
104 int s_pos, b2_spos,b3_spos;
\r
106 for (int y = size.h - 1-8; y >= 8; y--) {
\r
107 line_ptr = y*size.w;
\r
116 for (; x >= 0; x--) {
\r
117 if (raster_buf[line_ptr+x] == 0) {
\r
118 // 検出条件確認:w1は2以上欲しいな。
\r
119 if (!check_w1(w1)) {
\r
135 for (; x >= 0; x--) {
\r
136 if (raster_buf[line_ptr+x] > 0) {
\r
137 // 検出条件確認:b1は1以上欲しいな。
\r
138 if (!check_b1(b1)){
\r
153 for (; x >= 0; x--) {
\r
154 if (raster_buf[line_ptr+x] == 0) {
\r
155 // 検出条件確認:w2*10/b1は80-120以上欲しいな。
\r
156 if (!check_w2(b1,w2)) {
\r
157 //条件不十分→w2→w1として、b1を解析
\r
175 for (; x >= 0; x--) {
\r
176 if (raster_buf[line_ptr+x] > 0){
\r
177 //条件:(w1+b1)/2の2~4倍
\r
179 if (!check_b2(b1,b2)) {
\r
180 // b2->b1と仮定して解析しなおす。
\r
181 if(check_w1(w2) && check_b1(b2)){
\r
203 for (; x >= 0; x--) {
\r
204 if (raster_buf[line_ptr+x] == 0){
\r
205 if (!check_w3(w2,w3)) {
\r
206 //w2→w1,b2->b1として解析しなおす。
\r
207 if(check_w1(w2) && check_b1(b2)){
\r
230 for (; x >= 0; x--) {
\r
231 if (raster_buf[line_ptr+x] > 0) {
\r
233 if (!check_b3(b3,b1)) {
\r
234 if(check_w1(w2) && check_b1(b2)){
\r
235 //条件不十分→b3->b1,w3->w1として再解析
\r
254 item = this._result.prePush();
\r
264 throw new NyARException();
\r