by chmod775 · 13y ago · 0 comments
Except it does break the captcha in 23 lines. I don't get your point.
Why would he need to do any 'un-swirling' in the first place? That's not the point of the captcha. The captcha provides you with multiple images and you have to pick the least swirled one - which is exactly what his code does.
And you argue that because he did use external libraries it's not 23 lines of python. Of course it is. He had to write only 23 lines that make up the logic to break the captcha. If you'd argue that one would have to add any previous work (or lines) done by other people to the linecount of your own project, I could also argue that 'print("Hello")' is not one line of python, because it uses some standard python library, which in turn calls native code, that native code would make a few syscalls and at some point resulting in multiple hundred lines of compiled kernel C code being executed.
So the linecount of his 23 lines python script would actually be: 23 lines of python + various libraries + the entire Linux kernel = roughly 20 million lines of code. Good job.
And yes, that was nitpicking. And I'm angry for some reason.
When someone publishes code and says something like "solved <problem> in <n lines> of <pick your language>" there generally is an implied "my language is better than yours" subliminal message that, for some strange reason, is based on line count.
Let's not debate the merit of line count as a measure of how good a language may or may not be. If we are going to go there I'll write the same solution in APL and we'll start counting characters instead. Again, line or character count, in my opinion, is not a measure of the "superiority" of a language.
The 28 line solution is not pure Python. How do we define pure Python. Let's just say that "solved <problem> in <n lines> of Python" to me means that you download and install Python:
http://www.python.org/download/releases/2.7.3/
Install nothing else whatsoever and write code that solves <problem>.
OpenCV, which is what the author used for a couple of aspects of this code, is an extensive (and really cool) C++ library that is being accessed from Python. Here's the source:
https://github.com/Itseez/opencv
I'll leave it up to the reader to find the source for the Sobel method.
A much more honest title could have included something like "solving <problem> with <n> lines of Python using OpenCV".
As I said before, the intent of the article and what is being demonstrated are good, no, great. I just wish the title was a little more reflective of reality. That's all. No need to get worked-up. This is not that serious of an issue. Just a comment.
I agree with him. If it's wrapped up in a library and it's distributed by a package manager then it doesn't count towards the total SLOC of your project.
>If it's wrapped up in a library and it's distributed by a package manager then it doesn't count towards the total SLOC of your project.
Think about what you are saying. With that logic I can write a library in C++ that evaluates all images in the current working directory for least edge length and returns the name or index of the winning file. My Python program, then, might look something like this:
import magic
print magic.evaluate()
And then I claim that I have written a program that solves a swirly CAPCHA in two lines of Python.C'mon.
I you want to count true Python lines, download the language from python.org and write a solver without the use of any add-on libraries. Then we can talk about Python lines.
OK, I didn't write the JPEG decoder, but how far do you want me to go?!
> If you had to write the un-swirling, gray-scaling, Sobel filtering and summation code in Python you'd be looking at a much larger pile-o-code
I would also like to point out these are also all very simple operations, which would only take a few lines of Python/C/whatever to do. Python just happens to have a pre-written libraries to save reinventing the wheel.
Yikes! They are not. That's a lot of code. I've done a ton of image processing work in both hardware (FPGA) and software (various languages). Swirling, gray-scaling, Sobel filtering and summation collectively are far from "a few lines of Python/C/whatever to do"
> Python just happens to have a pre-written libraries to save reinventing the wheel
That's not true. OpenCV is NOT a Python library, it's nearly 100% C++ as far as I can tell:
https://github.com/Itseez/opencv
That was, in many ways, my point. This is not a solution in 23 lines of Python. Go install Python from Python.org --and NOTHING ELSE-- and solve the problem. Let's see how many lines of Python it takes.
There's nothing wrong with the intent of the author in terms of showing how one can break these CAPTCHA's using edge-length evaluation. I never put any thought into this myself so, yes, I learned something of value from his post. I just wish the title was more genuine, that's all.
RGB to grayscale: V = r x g x b/3 (one line).
The Sobel operation is at most 4 nested loops (really only 3) for a total of ~7 lines of code, depending on how you like your white space.
Fold the summation into your Sobel function without requiring another line.
The most complicated thing used from the OpenCV library (which I'm well aware is C++!) is JPEG decoding. OK, I'm avoiding swirling, but then it isn't needed to solve the CAPTCHA anyway.
Oh, BTW, "V = r x g x b/3" is incorrect. This is not you convert a color image to a grayscale image.