次期ふぇらほいの副産物 By-product of next-fellahoi

どうもえりっくです。

いま、ふぇらふぇらほいほいにアイコン画像からふぇら子の判定をできないかを模索中です。

イコン画像を取ってくるときの結構APIを消費してしまうという問題は見ないことにします・・・

まず当初の思いつきとして
サンプリングした画像データを照合させれば余裕じゃねwwwという考え。

あちこちからTwitterで【急募】してアイコン画像集めた結果。






あいつらノイズ入れてやがる
単純にバイナリ比較じゃうまくいかない・・・

次に考えたのが
イコン画像のサイズみてみるのはどう?


ブログやライブラリを回って、ようやく書き上げました。

「小さな星がほらひとつ」さん http://d.hatena.ne.jp/WorldWorldWorld/20091119/1258645640
「しいしせねっと」さん http://siisise.net/jpeg.html
にお世話になりました。。。

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
typedef unsigned char byte;

/**************************************************
 Function getJpegImageSize[3arg]
  <ReturnValue>
    -1 : Failed to open the file.
	-2 : File is not JPEG file.
	1  : Succeed.
 **************************************************/
int getJpegImageSize(const char fileName[], int* width, int* height) {
	byte data[4];
	FILE *file = fopen(fileName, "rb");
	
	if(file == NULL) return -1; // Failed to open file
	fread(data, 1, 2, file); // Read SOI segment
	if(data[0] != 0xFF || data[1] != 0xD8) return -2; // This is not JPEG file
	while(1) {
		fread(data, 1, 2, file);
		if(data[0] == 0xFF) { // It's marker
			if(data[1] == 0xC0 || data[1] == 0xC2) { // Additionally it's SOF0 segment
				fread(data, 1, 3, file); // Skip 3byte
				fread(data, 1, 4, file);
				*width  = MAKEWORD(data[3], data[2]);
				*height = MAKEWORD(data[1], data[0]);
				return 1;
			} else { // It's not SOF0 segment
				size_t len;
				byte* skipBuffer;
				fread(data, 1, 2, file);
				len = MAKEWORD(data[1], data[0]) - 2;
				skipBuffer = (byte*)malloc(sizeof(byte) * len);
				fread(skipBuffer, 1, len, file);
				free(skipBuffer);
			}
		}
	}
}


int main(int argc, char* argv[]) {
	int i, width, height;
	FILE *file;
	
	if(argc < 2) {
		fprintf(stderr, "Specify the argument. \n");
		return 1;
	}
	
	for(i = 1; i < argc; i++) {
		int err;
		if((err = getJpegImageSize(argv[i], &width, &height)) != 1) {
			if(err == -1) {
				fprintf(stderr, "%16s : Failed to open file\n", argv[i]);
				continue;
			} else if(err == -2) {
				fprintf(stderr, "%16s : This file is not JPEG file\n", argv[i]);
				continue;
			}
		}
		printf("%16s : Width:%5d  Height : %5d\n", argv[i], width, height);
	}

	return 0;
}

サンプリングして、平均とって誤差でスパムか判断するプログラムを次回作ろうと思います。
まずは画像サイズで勝負だ!!!スパム!!!!!


Hi, I'm Eric.
Now, is trying to judge whether it's spam or not by using icon.
I will disregard the problem that taking the icon image consumes API...

First, I thought that,
It's no problem by checking sampled image lololololol

Finally I found it.....





They insert noise to their icons
This problem will not be able to solve by checking binary data...

Next, I thought that,
How about check the width and height of icon?
I referred to blog and library, and I wrote it.


I'll code the program that samples the image, takes the average,
and compare by the error margin to judge whether it's spam or not.
First of all, let's fight by the image size, Spam!!!!!!!!!!