Programming/openCV2024. 1. 15. 10:48

 

일반적인 템플릿 매칭은 가장 매칭되는 하나의 녀석만 찾는데

트럼프 카드와 같이 여러개의 도형이 있을 경우 여러개를 다 찾는 방법을 제공함.

[링크 : https://pyimagesearch.com/2021/03/29/multi-template-matching-with-opencv/]

 

yolo 외에도 쓸 수 있는 방법이었나?

[링크 : https://pyimagesearch.com/2014/11/17/non-maximum-suppression-object-detection-python/]

 

openCV 문서에서도 발견

minMaxLoc을 안쓰면 되다고. (응?)

    res = cv.matchTemplate(img,template,method)
    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
    cv.rectangle(img,top_left, bottom_right, 255, 2)
res = cv.matchTemplate(img_gray,template,cv.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
    cv.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

[링크 : https://docs.opencv.org/3.4/d4/dc6/tutorial_py_template_matching.html]

 

아래 그림 하나로 설명.

원래 내가 원하던 건데.. x86이 아닌 arm에서도 되려나?

[링크 : https://medium.com/quantrium-tech/object-detection-multi-template-matching-2c9c9fc1a867]

[링크 : https://pypi.org/project/Multi-Template-Matching/]

'Programming > openCV' 카테고리의 다른 글

MTM + webcam  (0) 2024.01.16
opencv cv2.imshow() error  (0) 2024.01.16
cv2.imshow cv2.waitKey  (0) 2022.03.14
virtual mouse  (0) 2022.01.25
opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
Posted by 구차니
Programming/openCV2022. 3. 14. 19:38

imshow만 하면 검은 창만 비어서 나오는데

waitKey()로 메시지 루프(?)를 돌리지 않아서 그렇다고 한다.

 

[링크 : https://stackoverflow.com/questions/21810452]

'Programming > openCV' 카테고리의 다른 글

opencv cv2.imshow() error  (0) 2024.01.16
opencv를 이용한 다중 템플릿 추적  (0) 2024.01.15
virtual mouse  (0) 2022.01.25
opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
opencv face detect  (0) 2019.05.10
Posted by 구차니
Programming/openCV2022. 1. 25. 18:11

키즈카페에 있는 빔 프로젝터 + 카메라 식으로

카메라를 통해 사람을 인식하고 사람의 영역을 인식해 마우스 이벤트로 혹은

영역을 선택해 해당 영역의 객체를 터트리는 식으로 구현해볼까 고민중..

 

[링크 : https://pythonrepo.com/repo/HxnDev-Virtual-Mouse-using-OpenCV-python-computer-vision]

[링크 : https://thecodacus.com/posts/2021-12-14-gesture-recognition-virtual-mouse-using-opencv/]

'Programming > openCV' 카테고리의 다른 글

opencv를 이용한 다중 템플릿 추적  (0) 2024.01.15
cv2.imshow cv2.waitKey  (0) 2022.03.14
opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
opencv face detect  (0) 2019.05.10
vscode python3 opencv lint  (0) 2019.05.10
Posted by 구차니
Programming/openCV2021. 1. 14. 17:23

오랫만에 빌드하니 다 까먹었네 -_ㅠ

 

g++ myprog.cpp -lopencv_core -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -o myprog

[링크 : https://answers.opencv.org/question/165673]

 

 

아놔.. 에러 뿜뿜 -_-

/usr/bin/ld: warning: libopencv_imgproc.so.3.4, needed by //usr/local/lib/libopencv_dnn.so, may conflict with libopencv_imgproc.so.3.2
/usr/bin/ld: warning: libopencv_core.so.3.4, needed by //usr/local/lib/libopencv_dnn.so, may conflict with libopencv_core.so.3.2
/usr/bin/ld: /tmp/cc64nD60.o: undefined reference to symbol '_ZNK2cv3Mat5emptyEv'
/usr/bin/ld: //usr/local/lib/libopencv_core.so.3.4: error adding symbols: DSO missing from command line

 

+

아무튼 라즈베리 3B 에서 하는데

3.2.0이 설치되어 있고, 필요에 의해서 3.4.0을 빌드해서 설치했더니 3.2.0과 섞여서 난리가 났다.

그래서 -L 옵션을 통해 3.4.0이 설치된 곳을 우선적으로 보도록 해주니 문제없이 해결!

$ whereis libopencv_imgproc
libopencv_imgproc: /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.a /usr/local/lib/libopencv_imgproc.so

$ ls -al /usr/local/lib/libopencv_imgproc.so*
lrwxrwxrwx 1 root root      24 Jan 14 08:04 /usr/local/lib/libopencv_imgproc.so -> libopencv_imgproc.so.3.4
lrwxrwxrwx 1 root root      27 Jan 14 08:04 /usr/local/lib/libopencv_imgproc.so.3.4 -> libopencv_imgproc.so.3.4.13
-rw-r--r-- 1 root root 3292320 Jan 14 05:01 /usr/local/lib/libopencv_imgproc.so.3.4.13

$ ls -al /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so
lrwxrwxrwx 1 root root 24 Feb 12  2019 /usr/lib/arm-linux-gnueabihf/libopencv_imgproc.so -> libopencv_imgproc.so.3.2

$ g++ opencv_video.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib

 

 

 

 

MobileNet-SSD의 ssd_detect.cpp 빌드하려다가

아 몰라 대충 흑화중.. 후...

sudo apt-get install libcaffe-cpu-dev libcaffe-cpu1 libboost-all-dev libgflags-dev libgoogle-glog-dev libprotobuf-dev libopenblas-dev

$ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect
ssd_detect.cpp:15:10: fatal error: caffe/caffe.hpp: No such file or directory
 #include <caffe/caffe.hpp>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
pi@raspberrypi:~/src/MobileNet-SSD $ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect
In file included from /usr/include/caffe/blob.hpp:8,
                 from /usr/include/caffe/caffe.hpp:7,
                 from ssd_detect.cpp:15:
/usr/include/caffe/common.hpp:4:10: fatal error: boost/shared_ptr.hpp: No such file or directory
 #include <boost/shared_ptr.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

pi@raspberrypi:~/src/MobileNet-SSD $ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect
In file included from /usr/include/caffe/blob.hpp:8,
                 from /usr/include/caffe/caffe.hpp:7,
                 from ssd_detect.cpp:15:
/usr/include/caffe/common.hpp:5:10: fatal error: gflags/gflags.h: No such file or directory
 #include <gflags/gflags.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
$ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect
In file included from /usr/include/caffe/common.hpp:19,
                 from /usr/include/caffe/blob.hpp:8,
                 from /usr/include/caffe/caffe.hpp:7,
                 from ssd_detect.cpp:15:
/usr/include/caffe/util/device_alternate.hpp:34:10: fatal error: cublas_v2.h: No such file or directory
 #include <cublas_v2.h>
          ^~~~~~~~~~~~~
compilation terminated.

-DCPU_ONLY


 $ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect -DCPU_ONLY
In file included from /usr/include/caffe/util/math_functions.hpp:11,
                 from /usr/include/caffe/filler.hpp:13,
                 from /usr/include/caffe/caffe.hpp:9,
                 from ssd_detect.cpp:15:
/usr/include/caffe/util/mkl_alternate.hpp:14:10: fatal error: cblas.h: No such file or directory
 #include <cblas.h>
          ^~~~~~~~~
compilation terminated.

$ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect -DCPU_ONLY -lcaffe
/usr/bin/ld: /tmp/ccDNrn3i.o: undefined reference to symbol '_ZN6google4base21CheckOpMessageBuilder7ForVar2Ev'
/usr/bin/ld: //lib/arm-linux-gnueabihf/libglog.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status


$ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect -DCPU_ONLY -lcaffe -lglog
/usr/bin/ld: /tmp/ccO8VjqT.o: undefined reference to symbol '_ZN6google26ShowUsageWithFlagsRestrictEPKcS1_'
/usr/bin/ld: //lib/arm-linux-gnueabihf/libgflags.so.2.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status




$ g++ ssd_detect.cpp -lopencv_core -lopencv_dnn -lopencv_imgproc -lopencv_videoio -lopencv_highgui -lopencv_objdetect -lopencv_imgcodecs -L/usr/local/lib -o ssd_detect -DCPU_ONLY -lcaffe -lgflags -lglog
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libcaffe.so, may conflict with libopencv_imgcodecs.so.3.4
/usr/bin/ld: warning: libopencv_imgproc.so.3.2, needed by /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libcaffe.so, may conflict with libopencv_imgproc.so.3.4
/usr/bin/ld: warning: libopencv_core.so.3.2, needed by /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/libcaffe.so, may conflict with libopencv_core.so.3.4

 

 

caffe 빌드

위에 lib들 설치하고 아래것 추가로 설치

sudo apt-get install protobuf-compiler libhdf5-dev liblmdb-dev libleveldb-dev libatlas-base-dev python-numpy

 

sudo apt-get install protobuf-compiler

[링크 : https://stackoverflow.com/questions/46698260/could-not-find-protobuf-compiler]

 

sudo apt-get install libhdf5-dev

[링크 : https://github.com/jcjohnson/torch-rnn/issues/121]

 

sudo apt-get install liblmdb-dev

[링크 : https://caffe.berkeleyvision.org/install_apt.html]

 

Could NOT find LevelDB

sudo apt-get install libleveldb-dev

 

Could NOT find Atlas

sudo apt-get install libatlas-base-dev

 

Could NOT find NumPy

sudo apt-get install python-numpy

[링크 : https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/306]

 

'Programming > openCV' 카테고리의 다른 글

cv2.imshow cv2.waitKey  (0) 2022.03.14
virtual mouse  (0) 2022.01.25
opencv face detect  (0) 2019.05.10
vscode python3 opencv lint  (0) 2019.05.10
opencv cannyedge  (0) 2019.01.16
Posted by 구차니
Programming/openCV2019. 5. 10. 19:17

 

 

import cv2

 

dirname = '/home/user/.local/lib/python3.6/site-packages/cv2/data/'

 

face_cascade = cv2.CascadeClassifier(dirname + 'haarcascade_frontalface_default.xml')

eye_cascade = cv2.CascadeClassifier(dirname + 'haarcascade_eye.xml')

 

cam = cv2.VideoCapture(0)

cam.set(3, 160) # CV_CAP_PROP_FRAME_WIDTH

cam.set(4, 120) # CV_CAP_PROP_FRAME_HEIGHT

cam.set(5, 60) # CV_CAP_PROP_FPS

print(cam.get(3))

print(cam.get(4))

print(cam.get(5))

 

while True:

ret_val, img = cam.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

 

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

print(faces)

for (x, y, w, h) in faces:

img = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

roi_gray = gray[y:y+h, x:x+w]

roi_color = img[y:y+h, x:x+w]

eyes = eye_cascade.detectMultiScale(roi_gray)

for (ex, ey, ew, eh) in eyes:

cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)

 

cv2.imshow("Cam Viewer", img)

cv2.imshow("Cam Viewer gray", gray)

if cv2.waitKey(1) == 27:

break

 

[링크 : https://opencv-python-tutroals.readthedocs.io/.../py_face_detection/py_face_detection.html]

[링크 : https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale]

'Programming > openCV' 카테고리의 다른 글

virtual mouse  (0) 2022.01.25
opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
vscode python3 opencv lint  (0) 2019.05.10
opencv cannyedge  (0) 2019.01.16
opencv 원 추정  (0) 2019.01.16
Posted by 구차니
Programming/openCV2019. 5. 10. 19:05

 

{

"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"]

}

[ : https://github.com/Microsoft/vscode-python/issues/2879]

'Programming > openCV' 카테고리의 다른 글

opencv-3.4.0 어플리케이션 빌드  (0) 2021.01.14
opencv face detect  (0) 2019.05.10
opencv cannyedge  (0) 2019.01.16
opencv 원 추정  (0) 2019.01.16
OpenCV 분산처리  (0) 2018.04.25
Posted by 구차니
Programming/openCV2019. 1. 16. 19:13

cv2.Canny() 함수 사용법


[링크 : https://docs.opencv.org/3.1.0/da/d22/tutorial_py_canny.html]

'Programming > openCV' 카테고리의 다른 글

opencv face detect  (0) 2019.05.10
vscode python3 opencv lint  (0) 2019.05.10
opencv 원 추정  (0) 2019.01.16
OpenCV 분산처리  (0) 2018.04.25
openCV release mode와 debug mode 속도 차이  (0) 2018.03.19
Posted by 구차니
Programming/openCV2019. 1. 16. 19:10


[링크 : https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html]

[링크 : https://kr.mathworks.com/help/images/ref/imfindcircles.html]


[링크 : https://code.i-harness.com/ko-kr/q/96763b]

[링크 : http://k-imagineer.tistory.com/7]

[링크 : https://dreamaz.tistory.com/431]

[링크 : https://docs.opencv.org/3.4.1/.../group__imgproc__feature.html#ga47849c3be0d0406ad3ca45db65a25d2d]

'Programming > openCV' 카테고리의 다른 글

vscode python3 opencv lint  (0) 2019.05.10
opencv cannyedge  (0) 2019.01.16
OpenCV 분산처리  (0) 2018.04.25
openCV release mode와 debug mode 속도 차이  (0) 2018.03.19
openCV multicore support  (0) 2018.03.19
Posted by 구차니
Programming/openCV2018. 4. 25. 08:44

Odroid U3를 두개 묶어 놓다 보니 든 생각..

한대에서 영상 두개를 받고(USB로)

그 이미지중 하나(그러니까 사람으로 치면 오른눈-오른눈잡이)를 본인이 처리하고

다른쪽 영상 하나를 다른 시스템으로 넘겨서 처리하거나


아니면 각각 하나의 영상을 받아서

처리 결과만 다른쪽으로 넘겨주면 어떨까?


적고 보니 후자가 더 안정적일 수도 있겠네


[링크 : http://pachyderm.readthedocs.io/en/latest/getting_started/beginner_tutorial.html]

'Programming > openCV' 카테고리의 다른 글

opencv cannyedge  (0) 2019.01.16
opencv 원 추정  (0) 2019.01.16
openCV release mode와 debug mode 속도 차이  (0) 2018.03.19
openCV multicore support  (0) 2018.03.19
stitch / opencv / python  (0) 2016.07.18
Posted by 구차니
Programming/openCV2018. 3. 19. 10:38

각종 최적화랑 ASSERT 문으로 인해 속도 저하가 극심하니

릴리즈로 해라.. 정도?


[링크 : https://stackoverflow.com/.../opencv-slow-camera-framerate]

[링크 : https://stackoverflow.com/.../why-is-this-code-running-over-100-times-slower-in-debug-mode-than-release]

'Programming > openCV' 카테고리의 다른 글

opencv 원 추정  (0) 2019.01.16
OpenCV 분산처리  (0) 2018.04.25
openCV multicore support  (0) 2018.03.19
stitch / opencv / python  (0) 2016.07.18
opencv stitch  (0) 2016.07.14
Posted by 구차니