IT박스

Python으로 Wally를 어떻게 찾습니까?

itboxs 2020. 10. 6. 08:00
반응형

Python으로 Wally를 어떻게 찾습니까?


뻔뻔하게 악 대차에 뛰어 들다 :-)

Mathematica 를 사용하여 Waldo를 찾는 방법과 R을 사용 하여 Waldo를 찾는 방법에 영감을 얻었습니다 . 새로운 Python 사용자로서 어떻게이 작업을 수행 할 수 있는지보고 싶습니다. Python이 R보다 여기에 더 적합 할 것 같으며 Mathematica 또는 Matlab에서와 같이 라이선스에 대해 걱정할 필요가 없습니다.

아래 예제와 같은 예에서는 단순히 스트라이프를 사용하면 작동하지 않습니다. 이와 같은 어려운 예에서 간단한 규칙 기반 접근 방식이 작동하도록 만들 수 있다면 흥미로울 것입니다.

해변에서

정답은 원래 스레드에서 Gregory Klopper가 옹호 한 RBM (Restricted Boltzmann Machine) 접근 방식과 같은 ML 기술을 사용해야한다고 믿기 때문에 [machine-learning] 태그를 추가했습니다. Python에서 사용할 수있는 RBM 코드 가 있습니다.이 코드시작하기에 좋은 곳일 수 있지만 분명히 해당 접근 방식을 위해서는 훈련 데이터가 필요합니다.

신호 처리를위한 머신 러닝 (MLSP 2009)에 대한 2009 년 IEEE 국제 워크숍에서 그들은 데이터 분석 대회 : 월리가 어디 있습니까? . 훈련 데이터는 MATLAB 형식으로 제공됩니다. 해당 웹 사이트의 링크는 작동하지 않지만 데이터 ( Sean McLoone 및 동료가 취한 접근 방식의 출처와 함께 여기 에서 찾을 수 있음)는 여기 에서 찾을 수 있습니다 (SCM 링크 참조).


다음은 mahotas를 사용한 구현입니다 .

from pylab import imshow
import numpy as np
import mahotas
wally = mahotas.imread('DepartmentStore.jpg')

wfloat = wally.astype(float)
r,g,b = wfloat.transpose((2,0,1))

빨강, 녹색 및 파랑 채널로 분할합니다. 아래의 부동 소수점 산술을 사용하는 것이 더 낫기 때문에 상단에서 변환합니다.

w = wfloat.mean(2)

w 흰색 채널입니다.

pattern = np.ones((24,16), float)
for i in xrange(2):
    pattern[i::4] = -1

세로축에 + 1, + 1, -1, -1 패턴을 만듭니다. 이것은 월리의 셔츠입니다.

v = mahotas.convolve(r-w, pattern)

빨간색 빼기 흰색으로 컨볼 루션합니다. 이것은 셔츠가있는 곳에 강한 반응을 줄 것입니다.

mask = (v == v.max())
mask = mahotas.dilate(mask, np.ones((48,24)))

최대 값을 찾고 확장하여 표시되도록합니다. 이제 지역이나 관심사를 제외한 전체 이미지를 어둡게합니다.

wally -= .8*wally * ~mask[:,:,None]
imshow(wally)

그리고 우리는 얻는다 왈도!


템플릿 매칭을 시도한 다음 가장 유사성이 높은 항목을 삭제 한 다음 머신 러닝을 사용하여 범위를 더 좁힐 수 있습니다. 그것은 또한 매우 어렵고 템플릿 매칭의 정확성으로 모든 얼굴 또는 얼굴과 같은 이미지를 반환 할 수 있습니다. 이 일을 지속적으로 수행하려면 기계 학습 이상의 것이 필요하다고 생각합니다.


문제를 두 개의 작은 문제로 나누는 것으로 시작해야합니다.

  1. 사람과 배경을 구분하는 알고리즘을 만듭니다.
  2. 가능한 한 많은 긍정 및 부정 예제로 신경망 분류기를 훈련하십시오.

those are still two very big problems to tackle...

BTW, I would choose c++ and open CV, it seems much more suited for this.


This is not impossible but very difficult because you really have no example of a successful match. There are often multiple states(in this case, more examples of find walleys drawings), you can then feed multiple pictures into an image reconization program and treat it as a hidden markov model and use something like the viterbi algorithm for inference ( http://en.wikipedia.org/wiki/Viterbi_algorithm ).

Thats the way I would approach it, but assuming you have multiple images that you can give it examples of the correct answer so it can learn. If you only have one picture, then I'm sorry there maybe another approach you need to take.


I recognized that there are two main features which are almost always visible:

  1. the red-white striped shirt
  2. dark brown hair under the fancy cap

So I would do it the following way:

search for striped shirts:

  • filter out red and white color (with thresholds on the HSV converted image). That gives you two mask images.
  • add them together -> that's the main mask for searching striped shirts.
  • create a new image with all the filtered out red converted to pure red (#FF0000) and all the filtered out white converted to pure white (#FFFFFF).
  • now correlate this pure red-white image with a stripe pattern image (i think all the waldo's have quite perfect horizontal stripes, so rotation of the pattern shouldn't be necessary). Do the correlation only inside the above mentioned main mask.
  • try to group together clusters which could have been resulted from one shirt.

If there are more than one 'shirts', to say, more than one clusters of positive correlation, search for other features, like the dark brown hair:

search for brown hair

  • filter out the specific brown hair color using the HSV converted image and some thresholds.
  • search for a certain area in this masked image - not too big and not too small.
  • now search for a 'hair area' that is just above a (before) detected striped shirt and has a certain distance to the center of the shirt.

Here's a solution using neural networks that works nicely.

신경망은 그림에서 Wally가 나타나는 위치를 나타내는 경계 상자로 표시된 몇 가지 해결 된 예제에서 훈련됩니다. 네트워크의 목표는 훈련 / 검증 데이터에서 예측 된 상자와 실제 상자 사이의 오류를 최소화하는 것입니다.

위의 네트워크는 Tensorflow Object Detection API를 사용하여 학습 및 예측을 수행합니다.

참고 URL : https://stackoverflow.com/questions/8849869/how-do-i-find-wally-with-python

반응형