반응형

 

 

 

 

 

 

USB 웹캠을 하나 주워 왔는데 동작이 잘돼서 라즈베리파이에 달아주기로 했습니다.

 

웹캠 제품은 Logitech Orbit/Sphere AF입니다. 

 

uvcdynctrl 를 통해서 webcam에 Pan/Tilt를 조정할 예정입니다. 

 

 

0. uvcdynctrl 설치

sudo apt-get install uvcdynctrl 

 

 

1. uvdynctrl 도움말

uvcdynctrl -h

 

 

 

2. uvdynctrl 사용 가능한 장치 리스트 확인

uvcdynctrl -c

 

 

 

2. uvdynctrl 컨트롤

Controls that work

# uvcdynctrl -s "Pan/tilt Reset" -- 1
# uvcdynctrl -s "Pan/tilt Reset" -- 2
# uvcdynctrl -s "Pan/tilt Reset" -- 3

# uvcdynctrl -s "Pan (relative)" -- -700
$ uvcdynctrl -s "Pan (relative)" -- 700

# uvcdynctrl -s "Tilt (relative)" -- -500
# uvcdynctrl -s "Tilt (relative)" -- 500

# uvcdynctrl -s "Brightness" -- 1
# uvcdynctrl -s "Brightness" -- 255

# uvcdynctrl -s "Contrast" -- 1
# uvcdynctrl -s "Contrast" -- 255

# uvcdynctrl -s "Saturation" -- 1
# uvcdynctrl -s "Saturation" -- 255

# uvcdynctrl -s "Gain" -- 1
# uvcdynctrl -s "Gain" -- 255

# uvcdynctrl -s "Backlight Compensation" -- 0
# uvcdynctrl -s "Backlight Compensation" -- 1
# uvcdynctrl -s "Backlight Compensation" -- 2


# uvcdynctrl -s "Power Line Frequency" -- 0
# uvcdynctrl -s "Power Line Frequency" -- 1
# uvcdynctrl -s "Power Line Frequency" -- 2

# uvcdynctrl -s "White Balance Temperature" -- x

# uvcdynctrl -s "LED1 Mode" -- 0 LED off
# uvcdynctrl -s "LED1 Mode" -- 1 LED on
# uvcdynctrl -s "LED1 Mode" -- 2 LED blinking
# uvcdynctrl -s "LED1 Mode" -- 3 LED on

# 장치가 여러개 잡혀있을 때 명시적으로 지정
# uvcdynctrl ( --device=video0 ) -s "Pan/tilt Reset" -- 1

 

 

3. uvdynctrl 문제

 

a. uvdynctrl이 오래된 라이브러리이고, 더 이상 업데이트가 안됨.

b. tilt는 되지만, pan이 명령이 없음. 저 같은 경우는 추가해주었기 때문에 'pan (relative)'가 있습니다.

 

명령 추가해줍니다.

sudo vim /usr/share/uvcdynctrl/data/046d/logitech.xml

문자열 찾기 : V4L2_CID_PAN_RELATIVE

2008년도에 Pan 관련해서 업데이트를 했다고 합니다. 

 

문자열 찾기 : V4L2_CID_TILT_RELATIVE

 

저 같은 경우는 노란색으로 부분 ID 쪽에 공백으로 돼있었습니다. 

 

V4L2_CID_PAN_RELATIVE 추가해주면 됩니다. 

 

추가가 되었으면, 

uvcdynctrl --import=/usr/share/uvcdynctrl/data/046d/logitech.xml

 

혹시 모르니 재부팅도 해줍니다.

sudo reboot

 

 

 

4. 그래도 안 될 경우 

 

docs.ros.org/en/jade/api/tuw_uvc/html/dynctrl-logitech_8h.html#a193f86e1414943187cb3c847358c0275

 

tuw_uvc: dynctrl-logitech.h File Reference

Go to the source code of this file. Define Documentation Value: { \ 0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, \ 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x56 \ } Definition at line 36 of file dynctrl-logitech.h. Value: { \ 0x82, 0x06, 0x61, 0x63, 0x

docs.ros.org

혹시 모르니, 위 URL에 맞춰 value 값을 바꿉니다.

 

V4L2_CID_PAN_RELATIVE = 0x009A0904 
V4L2_CID_PAN_RESET = 0x009A0906
V4L2_CID_TILT_RELATIVE = 0x009A0905 
V4L2_CID_TILT_RESET = 0x009A0907

 

 

728x90
반응형
반응형

 

안녕하세요. 

 

만약, 처음 이 글을 보신다면 아래 글을 먼저 읽어보시는 것을 추천드립니다.

 

1편 : Coral Board 대신 라즈베리파이를 사용하는 이유 : https://coding-yoon.tistory.com/85?category=866905

2편 : USB Accelerator(Edge TPU) 환경설정 : https://coding-yoon.tistory.com/87?category=866905

3편 : Coral Edge TPU 예제 돌리기 : https://coding-yoon.tistory.com/88

 

 

이 그림을 이해하기만 하면 끝!

Edge TPU는 CNN과 같은 Deep feed-forward 신경망을 실행할 수 있습니다.

 

8비트 Edge TPU 용으로 컴파일 된 TensorFlow Lite 모델만 지원하며, 32비트 TensorFlow는 지원하지 않습니다. 

 

Tensor Lite로 직접 모델을 학습시킬 수 없고, Transfer Learning(전이 학습)을 통해 모델을 향샹시킬 수 있습니다.

 

TensorFlow(.pb)나 Keras(.h5)(32bit)를  통해 학습된 모델을 TensorFlow Lite Converter를 사용하여 TensorFlow 파일에서 TensorFlow Lite (.tflite)로 모델을 변환해야합니다. 

 

 

<참고> 

저는 Coral로 개발을 할 때 개인적으로 Keras를 추천드리고 싶습니다. 

 

Edge TPU가 모든 연산을 하는 것은 아닙니다. 공식 홈페이지에서 Edge TPU가 지원하는 연산들을 소개합니다. 

 

모바일넷과 같은 경량 모델에서 사용하는 연산들을 지원하며, 예제들 또한 Keras모델을 불러와 학습시켰습니다.

 

예를 들면 Depthwise Seperable Convolution을 찾을 수 있고, 경량 모델 : MobileNet,  Xception 등을 볼 수 있습니다.

https://coding-yoon.tistory.com/77?category=825914

 

[딥러닝] Depthwise Separable Covolution with Pytorch( feat. Convolution parameters VS Depthwise Separable Covolution paramet

안녕하세요. Google Coral에서 학습된 모델을 통해 추론을 할 수 있는 Coral Board & USB Accelator 가 있습니다. 저는 Coral Board를 사용하지 않고, 라즈베리파이4에 USB Accelator를 연결하여 사용할 생각입니..

coding-yoon.tistory.com

Coral에서 만든 예제들

 

 

우선, TensorFlow나 Keras로 학습된 모델을 저장해야 합니다. 

 

TensorFlow로 학습했다면, (.pb)파일,

Keras로 학습했다면 (.h5)파일

 

 

학습된 모델(32bit)을 TensorFlow Lite Converter(8bit)로 변환해야합니다.

 

변환한 모델을 저장합니다.

 

이제 모델이 준비가 끝났습니다. 최소한의 코드로 작성했습니다.

불러오기

Operation name

Runtime version*

Known limitations

Add

All

 

AveragePool2d

All

No fused activation function.

Concatenation

All

No fused activation function.
If any input is a compile-time constant tensor, there must be only 2 inputs, and this constant tensor must be all zeros (effectively, a zero-padding op).

Conv2d

All

Must use the same dilation in x and y dimensions.

DepthwiseConv2d

12

Dilated conv kernels are not supported.

13

Must use the same dilation in x and y dimensions.

ExpandDims

13

 

FullyConnected

All

Only the default format is supported for fully-connected weights. Output tensor is one-dimensional.

L2Normalization

All

 

Logistic

All

 

Maximum

All

 

MaxPool2d

All

No fused activation function.

Mean

12

No reduction in batch dimension. Supports reduction along x- and/or y-dimensions only.

13

No reduction in batch dimension. If a z-reduction, the z-dimension must be multiple of 4.

 

지원하는 연산입니다. 지원하는 연산을 더 보고 싶으시면 아래 주소를 달아놓을테니 보시면 좋을 것 같습니다.

 

 

파란색 Input_data가 추론하고자 하는 실제 데이터입니다. 

 

input쪽이 코드가 길어져 input_tensor로 따로 함수화를 시켰습니다.

Coral 공식 GitHub예제를 따라했습니다.

 

output쪽은 그렇게 길지 않기 때문에 tensorflow lite 공식 홈페이지를 따라했습니다.

 

추론을 시작하는 코드는 Interpreter.invoke()입니다.

 

추론을 완료하면 output_data에 추론 값이 담겨 있습니다.

 

 

다음 글은 간단한 모델을 하나 불러와 실제로 추론을 한 번 해보겠습니다. 

 

https://coral.ai/docs/edgetpu/models-intro/#compatibility-overview

https://www.tensorflow.org/tutorials/keras/save_and_load?hl=ko

https://www.tensorflow.org/lite/convert/python_api

https://coral.ai/docs/edgetpu/tflite-python/#load-tensorflow-lite-and-run-an-inference

https://www.tensorflow.org/api_docs/python/tf/lite/Interpreter

728x90
반응형

+ Recent posts