Changeset 389
- Timestamp:
- Jan 3, 2005, 10:48:54 PM (18 years ago)
- Location:
- pwntcha/trunk
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/configure.ac
r381 r389 19 19 AC_TYPE_SIZE_T 20 20 21 # Use OpenCV? 22 ac_cv_my_have_opencv="no" 23 save_CPPFLAGS="${CPPFLAGS}" 24 AC_PATH_PROG(OPENCV_CONFIG, opencv-config, no) 25 if test "${OPENCV_CONFIG}" != "no"; then 26 CPPFLAGS="${CPPFLAGS} `opencv-config --cflags`" 27 fi 28 AC_CHECK_HEADERS(cv.h, 29 [ac_cv_my_have_opencv="yes"], 30 [ac_cv_my_have_opencv="no"]) 31 CPPFLAGS="${save_CPPFLAGS}" 32 AM_CONDITIONAL(USE_OPENCV, test "${ac_cv_my_have_opencv}" = "yes") 33 21 34 # Use Imlib2? 22 35 ac_cv_my_have_imlib2="no" … … 32 45 AM_CONDITIONAL(USE_IMLIB2, test "${ac_cv_my_have_imlib2}" = "yes") 33 46 34 # Use Imlib2?35 ac_cv_my_have_opencv="no"36 save_CPPFLAGS="${CPPFLAGS}"37 AC_PATH_PROG(OPENCV_CONFIG, opencv-config, no)38 if test "${OPENCV_CONFIG}" != "no"; then39 CPPFLAGS="${CPPFLAGS} `opencv-config --cflags`"40 fi41 AC_CHECK_HEADERS(cv.h,42 [ac_cv_my_have_opencv="yes"],43 [ac_cv_my_have_opencv="no"])44 CPPFLAGS="${save_CPPFLAGS}"45 AM_CONDITIONAL(USE_OPENCV, test "${ac_cv_my_have_opencv}" = "yes")46 47 47 if test "${ac_cv_my_have_imlib2}" = "no" -a "${ac_cv_my_have_opencv}" = "no"; then 48 48 AC_MSG_ERROR([[cannot find Imlib2 or OpenCV, please install one of them]]) -
pwntcha/trunk/src/Makefile.am
r385 r389 4 4 pwntcha_CFLAGS = $(ADDITIONAL_CFLAGS) -Wall -O6 5 5 pwntcha_LDFLAGS = $(ADDITIONAL_LDFLAGS) 6 pwntcha_SOURCES = main.c image.c filters.c slashdot.c common.h6 pwntcha_SOURCES = main.c image.c filters.c common.h slashdot.c phpbb.c test.c 7 7 8 if USE_OPENCV 9 ADDITIONAL_CFLAGS = `opencv-config --cflags` 10 ADDITIONAL_LDFLAGS = `opencv-config --libs opencv highgui` 11 else 8 12 if USE_IMLIB2 9 13 ADDITIONAL_CFLAGS = `imlib2-config --cflags` -DX_DISPLAY_MISSING=1 10 14 ADDITIONAL_LDFLAGS = `imlib2-config --libs` 11 else12 if USE_OPENCV13 ADDITIONAL_CFLAGS = `opencv-config --cflags`14 ADDITIONAL_LDFLAGS = `opencv-config --libs opencv highgui`15 15 else 16 16 ADDITIONAL_CFLAGS = -
pwntcha/trunk/src/common.h
r387 r389 19 19 20 20 /* available CAPTCHA decoders */ 21 char * decode_slashdot(struct image *img); 21 char *decode_phpbb(struct image *img); 22 char *decode_slashdot(struct image *img); 23 char *decode_test(struct image *img); 22 24 23 25 /* image operations */ 24 struct image * image_load(char *name); 25 struct image * image_new(int width, int height); 26 struct image *image_load(char *name); 27 struct image *image_new(int width, int height); 28 void image_free(struct image *img); 29 void image_display(struct image *img); 26 30 int getgray(struct image *img, int x, int y, int *g); 27 31 int getpixel(struct image *img, int x, int y, int *r, int *g, int *b); … … 32 36 struct image *filter_fill_holes(struct image *img); 33 37 struct image *filter_detect_lines(struct image *img); 34 struct image *filter_equalize(struct image *img );38 struct image *filter_equalize(struct image *img, int threshold); 35 39 struct image *filter_trick(struct image *img); 36 40 struct image *filter_smooth(struct image *img); 37 41 struct image *filter_median(struct image *img); 42 struct image *filter_contrast(struct image *img); 38 43 -
pwntcha/trunk/src/filters.c
r387 r389 143 143 } 144 144 145 struct image *filter_equalize(struct image *img )145 struct image *filter_equalize(struct image *img, int threshold) 146 146 { 147 147 struct image *dst; … … 155 155 { 156 156 getpixel(img, x, y, &r, &g, &b); 157 if(r < 200) r = 50; else r = 200;157 if(r < threshold) r = 0; else r = 255; 158 158 setpixel(dst, x, y, r, r, r); 159 159 } … … 241 241 struct image *filter_median(struct image *img) 242 242 { 243 #define MSIZE 4243 #define MSIZE 3 244 244 struct image *dst; 245 245 int x, y, i, j, val[MSIZE*MSIZE]; … … 279 279 } 280 280 281 struct image *filter_contrast(struct image *img) 282 { 283 struct image *dst; 284 int histo[256]; 285 int x, y, i, min = 255, max = 0; 286 int r, g, b; 287 288 dst = image_new(img->width, img->height); 289 290 for(y = 0; y < img->height; y++) 291 for(x = 0; x < img->width; x++) 292 { 293 getgray(img, x, y, &r); 294 if(r < min) min = r; 295 if(r > max) max = r; 296 } 297 298 if(min == max) 299 histo[min] = 127; 300 else 301 for(i = min; i < max; i++) 302 histo[i] = (i - min) * 255 / (max - min); 303 304 for(y = 0; y < img->height; y++) 305 for(x = 0; x < img->width; x++) 306 { 307 getgray(img, x, y, &r); 308 setpixel(dst, x, y, histo[r], histo[r], histo[r]); 309 } 310 311 return dst; 312 } 313 -
pwntcha/trunk/src/image.c
r387 r389 16 16 #include "common.h" 17 17 18 #if defined(HAVE_IMLIB2_H) 19 # include <Imlib2.h> 20 #elif defined(HAVE_CV_H) 18 #if defined(HAVE_CV_H) 21 19 # include <cv.h> 22 20 # include <highgui.h> 21 #elif defined(HAVE_IMLIB2_H) 22 # include <Imlib2.h> 23 23 #else 24 24 # error "No imaging library" 25 25 #endif 26 26 27 struct image * 27 struct image *image_load(char *name) 28 28 { 29 struct image * img; 30 #if defined(HAVE_IMLIB2_H) 29 struct image *img; 30 #if defined(HAVE_CV_H) 31 IplImage *priv = cvLoadImage(name, -1); 32 #elif defined(HAVE_IMLIB2_H) 31 33 Imlib_Image priv = imlib_load_image(name); 32 #elif defined(HAVE_CV_H)33 IplImage * priv = cvLoadImage(name, -1);34 34 #endif 35 35 … … 38 38 39 39 img = malloc(sizeof(struct image)); 40 #if defined(HAVE_IMLIB2_H) 40 #if defined(HAVE_CV_H) 41 img->width = priv->width; 42 img->height = priv->height; 43 img->pitch = priv->widthStep; 44 img->channels = priv->nChannels; 45 img->pixels = priv->imageData; 46 #elif defined(HAVE_IMLIB2_H) 41 47 imlib_context_set_image(priv); 42 48 img->width = imlib_image_get_width(); … … 45 51 img->channels = 4; 46 52 img->pixels = (char *)imlib_image_get_data(); 47 #elif defined(HAVE_CV_H)48 img->width = priv->width;49 img->height = priv->height;50 img->pitch = priv->widthStep;51 img->channels = priv->nChannels;52 img->pixels = priv->imageData;53 53 #endif 54 54 img->priv = (void *)priv; … … 57 57 } 58 58 59 struct image * 59 struct image *image_new(int width, int height) 60 60 { 61 struct image * img; 62 #if defined(HAVE_IMLIB2_H) 61 struct image *img; 62 #if defined(HAVE_CV_H) 63 IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); 64 #elif defined(HAVE_IMLIB2_H) 63 65 Imlib_Image priv = imlib_create_image(width, height); 64 #elif defined(HAVE_CV_H)65 IplImage * priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);66 66 #endif 67 67 … … 70 70 71 71 img = malloc(sizeof(struct image)); 72 #if defined(HAVE_IMLIB2_H) 72 #if defined(HAVE_CV_H) 73 img->width = priv->width; 74 img->height = priv->height; 75 img->pitch = priv->widthStep; 76 img->channels = priv->nChannels; 77 img->pixels = priv->imageData; 78 #elif defined(HAVE_IMLIB2_H) 73 79 imlib_context_set_image(priv); 74 80 img->width = imlib_image_get_width(); … … 77 83 img->channels = 4; 78 84 img->pixels = (char *)imlib_image_get_data(); 79 #elif defined(HAVE_CV_H)80 img->width = priv->width;81 img->height = priv->height;82 img->pitch = priv->widthStep;83 img->channels = priv->nChannels;84 img->pixels = priv->imageData;85 85 #endif 86 86 img->priv = (void *)priv; 87 87 88 88 return img; 89 } 90 91 void image_free(struct image *img) 92 { 93 #if defined(HAVE_CV_H) 94 IplImage *iplimg; 95 iplimg = (IplImage *)img->priv; 96 cvReleaseImage(&iplimg); 97 #elif defined(HAVE_IMLIB2_H) 98 imlib_context_set_image(img->priv); 99 imlib_free_image(); 100 #endif 101 102 free(img); 89 103 } 90 104 … … 133 147 void image_display(struct image *img) 134 148 { 135 #if defined(HAVE_IMLIB2_H) 149 #if defined(HAVE_CV_H) 150 char name[BUFSIZ]; 151 sprintf(name, "Image %p (%i x %i)", img, img->width, img->height); 152 cvNamedWindow(name, 0); 153 cvShowImage(name, img->priv); 154 cvResizeWindow(name, img->width * 2, img->height * 2 + 50); 155 while((unsigned char)cvWaitKey(0) != 0x1b) 156 ; 157 #elif defined(HAVE_IMLIB2_H) 136 158 //char name[BUFSIZ]; 137 159 //static int i = 0; … … 140 162 //imlib_save_image(name); 141 163 //fprintf(stderr, "saved to %s\n", name); 142 #elif defined(HAVE_CV_H)143 char name[BUFSIZ];144 sprintf(name, "Image %p (%i x %i)", img, img->width, img->height);145 cvNamedWindow(name, 0);146 cvShowImage(name, img->priv);147 cvResizeWindow(name, 320, 120);148 164 #endif 149 165 } -
pwntcha/trunk/src/main.c
r388 r389 12 12 #include <stdio.h> 13 13 #include <stdlib.h> 14 #include <string.h> 14 15 #include <getopt.h> 15 16 … … 88 89 } 89 90 90 result = decode_slashdot(img); 91 if(!strcmp(mode, "test")) 92 result = decode_test(img); 93 else if(!strcmp(mode, "phpbb")) 94 result = decode_phpbb(img); 95 else if(!strcmp(mode, "slashdot")) 96 result = decode_slashdot(img); 97 else 98 { 99 if(img->width == 320 && img->height == 50) 100 result = decode_phpbb(img); 101 else if(img->height == 69) 102 result = decode_slashdot(img); 103 else 104 { 105 fprintf(stderr, "%s: could not guess CAPTCHA type\n", argv[0]); 106 printf("\n"); 107 image_free(img); 108 continue; 109 } 110 } 111 112 image_free(img); 113 91 114 if(!result) 92 115 { -
pwntcha/trunk/src/slashdot.c
r387 r389 31 31 /* Global stuff */ 32 32 struct { int xmin, ymin, xmax, ymax; } objlist[100]; 33 int objects = 0, first = -1, last = -1;33 int objects, first, last; 34 34 char *result; 35 35 … … 37 37 char * decode_slashdot(struct image *img) 38 38 { 39 struct image *tmp, *tmp2; 39 struct image *tmp1, *tmp2, *tmp3, *tmp4, *tmp5, *tmp6, *tmp7; 40 41 /* Initialise local data */ 42 objects = 0; 43 first = -1; 44 last = -1; 40 45 41 46 /* Slashdot captchas have 7 characters */ … … 43 48 44 49 /* Clean image a bit */ 45 tmp = filter_detect_lines(img);46 tmp = filter_fill_holes(tmp);50 tmp1 = filter_detect_lines(img); 51 tmp2 = filter_fill_holes(tmp1); 47 52 48 53 /* Detect small objects to guess image orientation */ 49 tmp 2 = filter_median(tmp);50 tmp 2 = filter_equalize(tmp2);51 count_objects(tmp 2);54 tmp3 = filter_median(tmp2); 55 tmp4 = filter_equalize(tmp3, 200); 56 count_objects(tmp4); 52 57 53 58 /* Invert rotation and find glyphs */ 54 tmp = rotate(tmp); 55 tmp = filter_median(tmp); 56 tmp = find_glyphs(tmp); 59 tmp5 = rotate(tmp2); 60 tmp6 = filter_median(tmp5); 61 tmp7 = find_glyphs(tmp6); 62 63 /* Clean up our mess */ 64 image_free(tmp1); 65 image_free(tmp2); 66 image_free(tmp3); 67 image_free(tmp4); 68 image_free(tmp5); 69 image_free(tmp6); 70 image_free(tmp7); 71 72 /* aaaaaaa means decoding failed */ 73 if(!strcmp(result, "aaaaaaa")) 74 result[0] = '\0'; 57 75 58 76 return result;
Note: See TracChangeset
for help on using the changeset viewer.