2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * These authors would like to acknowledge the Spanish Ministry of Industry,
19 * Tourism and Trade, for the support in the project TSI020301-2008-2
20 * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 * Mobile Dynamic Environments", led by Treelogic
22 * ( http://www.treelogic.com/ ):
24 * http://www.piramidepse.com/
27 package com.google.zxing.oned.rss.expanded;
29 import java.awt.image.BufferedImage;
31 import java.io.IOException;
32 import java.util.Hashtable;
34 import javax.imageio.ImageIO;
36 import com.google.zxing.BarcodeFormat;
37 import com.google.zxing.BinaryBitmap;
38 import com.google.zxing.NotFoundException;
39 import com.google.zxing.Result;
40 import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
41 import com.google.zxing.common.BitArray;
42 import com.google.zxing.common.GlobalHistogramBinarizer;
43 import org.junit.Assert;
44 import org.junit.Test;
47 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
48 * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
50 public final class RSSExpandedImage2stringTestCase extends Assert {
53 public void testDecodeRow2string_1() throws Exception {
54 String path = "test/data/blackbox/rssexpanded-1/1.jpg";
55 String expected = "(11)100224(17)110224(3102)000100";
57 assertCorrectImage2string(path, expected);
61 public void testDecodeRow2string_2() throws Exception {
62 String path = "test/data/blackbox/rssexpanded-1/2.jpg";
63 String expected = "(01)90012345678908(3103)001750";
65 assertCorrectImage2string(path, expected);
69 public void testDecodeRow2string_3() throws Exception {
70 String path = "test/data/blackbox/rssexpanded-1/3.jpg";
71 String expected = "(10)12A";
73 assertCorrectImage2string(path, expected);
77 public void testDecodeRow2string_4() throws Exception {
78 String path = "test/data/blackbox/rssexpanded-1/4.jpg";
79 String expected = "(01)98898765432106(3202)012345(15)991231";
81 assertCorrectImage2string(path, expected);
85 public void testDecodeRow2string_5() throws Exception {
86 String path = "test/data/blackbox/rssexpanded-1/5.jpg";
87 String expected = "(01)90614141000015(3202)000150";
89 assertCorrectImage2string(path, expected);
93 public void testDecodeRow2string_7() throws Exception {
94 String path = "test/data/blackbox/rssexpanded-1/7.png";
95 String expected = "(10)567(11)010101";
97 assertCorrectImage2string(path, expected);
101 public void testDecodeRow2string_10() throws Exception {
102 String path = "test/data/blackbox/rssexpanded-1/10.png";
103 String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)012345678901";
105 assertCorrectImage2string(path, expected);
109 public void testDecodeRow2string_11() throws Exception {
110 String expected = "(01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456";
111 String path = "test/data/blackbox/rssexpanded-1/11.png";
113 assertCorrectImage2string(path, expected);
117 public void testDecodeRow2string_12() throws Exception {
118 String expected = "(01)98898765432106(3103)001750";
119 String path = "test/data/blackbox/rssexpanded-1/12.jpg";
121 assertCorrectImage2string(path, expected);
125 public void testDecodeRow2string_13() throws Exception {
126 String expected = "(01)90012345678908(3922)795";
127 String path = "test/data/blackbox/rssexpanded-1/13.png";
129 assertCorrectImage2string(path, expected);
133 public void testDecodeRow2string_14() throws Exception {
134 String expected = "(01)90012345678908(3932)0401234";
135 String path = "test/data/blackbox/rssexpanded-1/14.png";
137 assertCorrectImage2string(path, expected);
141 public void testDecodeRow2string_15() throws Exception {
142 String expected = "(01)90012345678908(3102)001750(11)100312";
143 String path = "test/data/blackbox/rssexpanded-1/15.jpg";
145 assertCorrectImage2string(path, expected);
149 public void testDecodeRow2string_16() throws Exception {
150 String expected = "(01)90012345678908(3202)001750(11)100312";
151 String path = "test/data/blackbox/rssexpanded-1/16.jpg";
153 assertCorrectImage2string(path, expected);
157 public void testDecodeRow2string_17() throws Exception {
158 String expected = "(01)90012345678908(3102)001750(13)100312";
159 String path = "test/data/blackbox/rssexpanded-1/17.jpg";
161 assertCorrectImage2string(path, expected);
165 public void testDecodeRow2string_18() throws Exception {
166 String expected = "(01)90012345678908(3202)001750(13)100312";
167 String path = "test/data/blackbox/rssexpanded-1/18.jpg";
169 assertCorrectImage2string(path, expected);
173 public void testDecodeRow2string_19() throws Exception {
174 String expected = "(01)90012345678908(3102)001750(15)100312";
175 String path = "test/data/blackbox/rssexpanded-1/19.jpg";
177 assertCorrectImage2string(path, expected);
181 public void testDecodeRow2string_20() throws Exception {
182 String expected = "(01)90012345678908(3202)001750(15)100312";
183 String path = "test/data/blackbox/rssexpanded-1/20.jpg";
185 assertCorrectImage2string(path, expected);
189 public void testDecodeRow2string_21() throws Exception {
190 String expected = "(01)90012345678908(3102)001750(17)100312";
191 String path = "test/data/blackbox/rssexpanded-1/21.jpg";
193 assertCorrectImage2string(path, expected);
197 public void testDecodeRow2string_22() throws Exception {
198 String expected = "(01)90012345678908(3202)001750(17)100312";
199 String path = "test/data/blackbox/rssexpanded-1/22.jpg";
201 assertCorrectImage2string(path, expected);
205 public void testDecodeRow2string_25() throws Exception {
206 String expected = "(10)123";
207 String path = "test/data/blackbox/rssexpanded-1/25.png";
209 assertCorrectImage2string(path, expected);
213 public void testDecodeRow2string_26() throws Exception {
214 String expected = "(10)5678(11)010101";
215 String path = "test/data/blackbox/rssexpanded-1/26.png";
217 assertCorrectImage2string(path, expected);
221 public void testDecodeRow2string_27() throws Exception {
222 String expected = "(10)1098-1234";
223 String path = "test/data/blackbox/rssexpanded-1/27.png";
225 assertCorrectImage2string(path, expected);
229 public void testDecodeRow2string_28() throws Exception {
230 String expected = "(10)1098/1234";
231 String path = "test/data/blackbox/rssexpanded-1/28.png";
233 assertCorrectImage2string(path, expected);
237 public void testDecodeRow2string_29() throws Exception {
238 String expected = "(10)1098.1234";
239 String path = "test/data/blackbox/rssexpanded-1/29.png";
241 assertCorrectImage2string(path, expected);
245 public void testDecodeRow2string_30() throws Exception {
246 String expected = "(10)1098*1234";
247 String path = "test/data/blackbox/rssexpanded-1/30.png";
249 assertCorrectImage2string(path, expected);
253 public void testDecodeRow2string_31() throws Exception {
254 String expected = "(10)1098,1234";
255 String path = "test/data/blackbox/rssexpanded-1/31.png";
257 assertCorrectImage2string(path, expected);
261 public void testDecodeRow2string_32() throws Exception {
262 String expected = "(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012";
263 String path = "test/data/blackbox/rssexpanded-1/32.png";
265 assertCorrectImage2string(path, expected);
268 private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {
269 RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
271 BufferedImage image = ImageIO.read(new File(path));
272 BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
273 int rowNumber = binaryMap.getHeight() / 2;
274 BitArray row = binaryMap.getBlackRow(rowNumber, null);
276 Result result = rssExpandedReader.decodeRow(rowNumber, row, new Hashtable());
278 assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
279 assertEquals(expected, result.getText());