2015. 5. 25.

Camshift + Kalmanfilter with OpenCV & python on RaspberryPi B2 - object tracking robot for team project - 3

  Tilt 제어는 실험결과 비레제어만으로도 충분하다고 판단, 바로 pan 제어에 돌입했다.
Pan 제어는 360도 무한회전이 가능한 서보모터를 이용했다. (스테핑 모터를 써도 되지만 잠재적인 딜레이 문제와 하드웨어 구성 문제로 일단 손쉬운 서보모터를 사용했다.) on/off제어로 pan각을 제어했다.
 In Tilt test, we decided that only P control(P for PID control) was sufficient. We just get started control Pan angle. We used a continuous servo motor that can rotate 0~360*n degrees. (It could be a stepping motor instead, but we used a servo motor because of potential cycle delay problem.) We just use a on/off control method for Pan angle. 




동영상에서 보는 것처럼 어느정도 트래킹이 되는 것을 알 수 있다. 
이제 Pan각에 대해 더 세밀한 제어를 하도록하고, 간단하게 레이져와 비비탄청도를 부착하면 끝이다.

As you can see in this video, It tracked an object pretty good.
Now, we gonna control pan angle for detail. And finally we will attach laser module and BB gun.


2015. 5. 24.

Camshift + Kalmanfilter with OpenCV & python on RaspberryPi B2 - object tracking robot for team project - 2

자 이제 아두이노를 이용해서 팬틸트 제어를 해보자.

Let's control the Pan&Tilt angle using Arduino.



 이 동영상에서 보는 것 처럼 우선 pan&tilt각 제어 중에서 tilt각만 제어를 했다. 
Aruino Due를 사용해서 디지털서보모터를 이용해 0~90도 tilt각을 제어했다.

 As you can see in this video, I control a tilt angle first. 
Using Arduino Due and digital servo motor, I controlled tilt angle from 0 to 90 degrees.





 

 저번 글에도 올렸던 내용이지만, 더 고화질로 재촬영했다. 
라즈베리파이에 Camshift + Kalman filter를 적용한 코드의 결과로, 지정된 색을 잘 트래킹하는 것을 알 수 있다.

 This content is same in last post, but better quality.






  그리고나서, 라즈베리파이에서 물체의 중심좌표를 아두이노로 전송하면, 아두이노가 그에 맞게 카메라 tilt각도를 움직여서 트래킹하는 프로토타입을 만들었다. 처음에는 좌표계변환을 통해서 알맞은 tilt각을 계산하려고 했지만, 너무나도 많은 변수들(실제 그 각만큼 확실히 움직였는지, 축일치가 확실한지 등등..)이 너무 많아서 외부환경에 강건한 PID제어를 사용하기로 했다. 일단은 비례제어로 움직이게 했다.
  동영상의 끝부분에서 보면 알겠지만, 급정지하는 물체에 대해서 카메라의 출렁거림을 볼 수 있을 것이다. 즉 단순 P제어가 아닌, PID 제어가 필요하다는 것을 의미한다.

 Then, RPi send the center x, y data to arduino. The arduino control servo motor to control tilt angle. We built a prototype. At first, we tried to calculate tilt angle using coordinate transformation. But there are so many things to think. (Real moving angle, real axis coincidence, etc..) So we used a PID control that robust to external factors. Once we used P control.
 As you can see in this video ends, A camera is rocking when the object is suddenly stopped. This means that we not only P control but also PID control is needed.



  다음에는 tilt각에 PID제어를 적용하고, pan 각을 제어할 것이다. 그 후에는 레이져나 BB탄 총을 설치할 것이다. 완성이 곧 눈앞에 보인다.

 Next time, we apply PID control to tilt angle and control pan angle. After that, we attach Laser module or BB gun something.




2015. 5. 16.

TEWDA 로고

파워포인트로 만든 첫번째 로고







아래는 사운드

TEWDA is a blog. That means The Engineer Who Dreams of Arts



에이블톤으로 수정한 사운드.



사운드 링크 :

http://www.naturalreaders.com/    - 여기에서 UK. Graham 으로 선택했다.

2015. 5. 9.

코엑스 쇼핑몰 & 봉은사

<봉은사>

<쇼핑몰>

  내부적으로 리모델링이 끝나서 한번 가봐야지 가봐야지 했던 코엑스..
쇼핑몰을 다 구경하는데 하루종일 걸렸다. 그치만 신기한거 투성이 :D
다리는 아프지만 거의 모든 브랜드가 모여있어서 좋았다. (그러나 거의 아이쇼핑만 한게 함정)

그리고 바로 근처에 있는 봉은사 앞에서 구경하다가 날씨가 추워져서 돌아왔다.
벌써부터 석가탄신일 준비가 한창이었다.


터키요리 in coex

난 양고기랑 맞는 사람인듯
저런식의 요리는 너무 좋




  서비스로 스프와 빵을 먹었고, 양고기 구이와 밥, 감자튀김을 먹었다. 
양고기는 하얀색 소스에 찍어먹으면 일품.
  다른 요리는 크게 갈려진 콩을 튀긴 것이었는데 겉은 약간 딱딱하지만
안에는 상대적으로 부드러웠다. 이 가게에서 자신하는 요리라고 했는데, 과연 맛있었다.
상당히 맛있었고 (터키에서 살아도 될 만큼) 양도 좋았다 :-)


꽃이 너무 예뻐!



  초여름 치고 굉장히 더웠던 날씨.. 목 뒤가 다 타서 까졌다.
저기는 장미광장인가 그 쪽에 있는 미니 기차 레일 안쪽이다. 
역시 꽃은 예뻐!  :)

- 저번주 금요일 애버랜드에서 촬영

Camshift + Kalmanfilter with OpenCV & python on RaspberryPi B2 - object tracking robot for team project - 1

  최종적으로 만드려는 것은 물체를 파이카메라로 인식하여 tracking 및  요격(?) 하는 robot을 만드려는 것이다. 먼저 해야할 부분은 RaspberryPi B2(그나마 성능이 좋아서 선택)에서 Vision처리를 할 때 많이 쓰는 OpenCV 를 활용하여 물체의 색(HSV값)을 토대로 물체를 인식하는 코드를 만드는 것이다.

-Please understand through English is a bit wrong. ;) 
 I will make a robot that tracking an object with Pi Camera and Shut it down finally.
First,  I have to make a code for catch an object based on color(HSV) using RaspberryPi B2 and OpenCV.


  OpenCV를 사용하여 object tracking을 할 때 Camshift 알고리즘만으로는 안정적인 tracking이 불가능하다. 왜냐하면 Camshift만을 사용했을 경우에는 물체가 중간에 장애물 등에 의해 사라지거나 빠르게 움직일 경우 object를 놓치게 되기 때문이다. 따라서 Kalman filter(역시 독일인이 만듦)를 적용하여 노이즈를 적절히 제거하고, 움직임에 대한 경향을 토대로 Camshift의 탐색창을 재설정해줬다. 사용한 언어는 python이다.(python이 속도가 느리다고 하지만 새로 배우려는 목적이 컸으므로 python선택) 그리고 사용한 오픈소스를 손봐서 fps를 증가시켰다.

  If only use a Camshift algorithm in OpenCV, it would not be stable tracking. Because if you only use Camshift algorithm, it will be fail to track when an object is concealed by something or moving so fast that camera fps doesn't cover.
  Therefore we can apply a Kalman filter. A Kalman filter remove a noise appropriately and estimate a new object's position based on object's movement. I reset a Camshift search window by this estimated position. 
  I used a python(Although a python's speed is slow than C or C ++, I just use a python for learning). And I fixed a opensource for better fps. :)

동영상에서 보면 물체가 빠르게 움직여서 놓치게 된 경우에 예외처리를 통해 다시 물체를 재빠르게 catch하는 것을 볼 수 있다. 
또한 가려져도 다시 tracking을 한다.
만약 모니터에 화면을 출력하는 imshow를 사용하지 않는다면 fps는 더 증가하게 된다.  (전체 주기가 최대 0.3초, 평균 0.15초)
스펙이 제한적인 RPi에서 제법 쓸만한 성능이 나왔다.

In this video, you can see the exception handling for fast movement of an object. It recovered immediately. 
And it also tracks an object after concealed by something.
If it doesn't use a function 'imshow()', it will be more faster. (average cycle : 0.3sec -> 0.15sec)
The result is pretty enough although it is running on RPi.


최종적으로 만드려고 하는 tracking robot은 카메라 자체가 움직이기 때문에 위 동영상과 다르게 
카메라를 흔들었을 경우에도 tracking을 잘하는지 테스트한 결과이다.

Well, actually I will make a robot that move the camera itself. 
So as you see in this video, I conducted a shacking camera test.



  동영상 화질이 좋지않아 잘 보이지 않지만, 잘 tracking되는 것을 알 수 있다.
이제 RPi에서 추출한 target의 중심좌표를 UART통신을 통해 Arduino DUE로 보내는 부분만 추가하면 RPi에서 만들어야할 큰 틀은 완성이다. (이제 성능 쥐어짜기 및 마이너한 기능 추가에 돌입!!)

  Although video's quality is not good for recognize, It tracks very well.
Now, I will add a UART serial communication for RPi to Arduino DUE. After that, the big outline is finished.








참고문헌(reference) :

- Camshift 와 Kalmanfilter를 결합한 논문을 찾아서 어떤 알고리즘 순서로 적용하는지 참고함. (검색하면 쉽게 찾을 수 있음)
대충 설명하면 kalman으로 추정 -> 그곳을 camshift로 탐색 -> 측정한 값을 다시 kalman으로..

-OpenCV에 있는 Camshift를 이용해 python으로 짠 코드 (이 박사분 메일 답장도 칼 같아서 도움이 많이 되었음)
http://www.computervisiononline.com/blog/tutorial-using-camshift-track-objects-video

-Kalman 2D mouse tracking  python 코드 소스
https://github.com/simondlevy/OpenCV-Python-Hacks/tree/master/Kalman2D

-Kalman filter 이론 설명
http://www.matlabinuse.com/Mastering_MATLAB/43103

-OpenCV documentation 페이지
http://docs.opencv.org/

-Pi Camera documentation 페이지
http://picamera.readthedocs.org/en/release-1.10/api.html