'Programming/python(파이썬)'에 해당되는 글 81건

  1. 2024.02.28 cv2.ximgproc 없을 경우
  2. 2024.02.28 cv2.stereoBM + WLS
  3. 2024.02.28 matplotlib animation
  4. 2024.02.27 pip 패키지 관리
  5. 2024.02.26 pyhthon numpy 생략없이 출력
  6. 2024.02.22 matplotlib grayscale image to 3d graph
  7. 2024.01.22 python tcp 서버 예제
  8. 2024.01.17 파이썬 소켓 예제
  9. 2024.01.11 ipython notebook -> jupyter notebook
  10. 2024.01.09 파이썬 가상환경

contrib 패키지를 설치해주면 해결!

오늘자 기준으로 한 63MB 정도 된다. 꽤나 큰 편 인 듯

$ python3 depth.py 
Traceback (most recent call last):
  File "/home/minimonk/src/DisparityMapfromStereoPair/depth.py", line 17, in <module>
    right_matcher = cv.ximgproc.createRightMatcher(left_matcher);
AttributeError: module 'cv2' has no attribute 'ximgproc'

$ pip install opencv-contrib-python

[링크 : https://stackoverflow.com/questions/57427233/module-cv2-cv2-has-no-attribute-ximgproc]

'Programming > python(파이썬)' 카테고리의 다른 글

cv2.stereoBM + WLS  (0) 2024.02.28
matplotlib animation  (0) 2024.02.28
pip 패키지 관리  (0) 2024.02.27
pyhthon numpy 생략없이 출력  (0) 2024.02.26
matplotlib grayscale image to 3d graph  (0) 2024.02.22
Posted by 구차니

matplotlib을 3d로 그려보는 것 까지 통합완료. 이제 SGBM만 해보면 될 듯

WLS 필터 미적용 WLS 필터 적용

 

 

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
imgL = cv.imread('tsukuba_l.png', cv.IMREAD_GRAYSCALE)
imgR = cv.imread('tsukuba_r.png', cv.IMREAD_GRAYSCALE)
max_disparity=16
stereo = cv.StereoBM_create(max_disparity, blockSize=15)
disparity = stereo.compute(imgL,imgR)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# X, Y 좌표 생성
height, width = imgL.shape
x = np.arange(0, width, 1)
y = np.arange(0, height, 1)
x, y = np.meshgrid(x, y)

# 깊이 맵을 사용하여 Z 좌표 생성
z = disparity

# 3D 그래프에 표시
ax.plot_surface(x, y, z, cmap='viridis')

plt.show()

# WLS 필터 적용
right_matcher = cv.ximgproc.createRightMatcher(stereo);
left_disp = stereo.compute(imgL, imgR);
right_disp = right_matcher.compute(imgR, imgL);

# Now create DisparityWLSFilter
wls_filter = cv.ximgproc.createDisparityWLSFilter(stereo);

sigma = 1.5
lmbda = 8000.0

wls_filter.setLambda(lmbda);
wls_filter.setSigmaColor(sigma);
filtered_disp = wls_filter.filter(left_disp, imgL, disparity_map_right=right_disp);

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

z = filtered_disp

# 3D 그래프에 표시
ax.plot_surface(x, y, z, cmap='viridis')

plt.show()

 

'Programming > python(파이썬)' 카테고리의 다른 글

cv2.ximgproc 없을 경우  (0) 2024.02.28
matplotlib animation  (0) 2024.02.28
pip 패키지 관리  (0) 2024.02.27
pyhthon numpy 생략없이 출력  (0) 2024.02.26
matplotlib grayscale image to 3d graph  (0) 2024.02.22
Posted by 구차니

 

 

[링크 : https://matplotlib.org/stable/api/animation_api.html]

 

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')

def init():
    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(-1, 1)
    return ln,

def update(frame):
    xdata.append(frame)
    ydata.append(np.sin(frame))
    ln.set_data(xdata, ydata)
    return ln,

ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
                    init_func=init, blit=True)
plt.show()

[링크 : https://pythonprogramming.net/python-matplotlib-live-updating-graphs/]

[링크 : https://stackoverflow.com/questions/11874767/how-do-i-plot-in-real-time-in-a-while-loop]

 

+ 2024.03.14

import cv2
import matplotlib.pyplot as plt

def grab_frame(cap):
    ret,frame = cap.read()
    return cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)

#Initiate the two cameras
cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)

#create two subplots
ax1 = plt.subplot(1,2,1)
ax2 = plt.subplot(1,2,2)

#create two image plots
im1 = ax1.imshow(grab_frame(cap1))
im2 = ax2.imshow(grab_frame(cap2))

plt.ion()

while True:
    im1.set_data(grab_frame(cap1))
    im2.set_data(grab_frame(cap2))
    plt.pause(0.2)

plt.ioff() # due to infinite loop, this gets never called.
plt.show()

[링크 : https://stackoverflow.com/questions/44598124/update-frame-in-matplotlib-with-live-camera-preview]

 

matplotlib.pyplot.ion()[source]
Enable interactive mode.

See pyplot.isinteractive for more details.

See also

ioff
Disable interactive mode.

isinteractive
Whether interactive mode is enabled.

show
Show all figures (and maybe block).

pause
Show all figures, and block for a time.

[링크 : https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ion.html]

'Programming > python(파이썬)' 카테고리의 다른 글

cv2.ximgproc 없을 경우  (0) 2024.02.28
cv2.stereoBM + WLS  (0) 2024.02.28
pip 패키지 관리  (0) 2024.02.27
pyhthon numpy 생략없이 출력  (0) 2024.02.26
matplotlib grayscale image to 3d graph  (0) 2024.02.22
Posted by 구차니

pip도 아래 명령들을 이용하면 현재 패키지 버전들을 저정하고, 필요한 버전들을 설치할 수 있다.

python 프로젝트들이 나중에 버전이 꼬여서 난리나는거 보면

필수적인데 왜 다들 안쓸까..

 

pip list
pip freeze > requirements.txt

[링크 : https://intelloper.tistory.com/53]

 

pip install -r requirements.txt

[링크 : https://itholic.github.io/python-requirements/]

'Programming > python(파이썬)' 카테고리의 다른 글

cv2.stereoBM + WLS  (0) 2024.02.28
matplotlib animation  (0) 2024.02.28
pyhthon numpy 생략없이 출력  (0) 2024.02.26
matplotlib grayscale image to 3d graph  (0) 2024.02.22
python tcp 서버 예제  (0) 2024.01.22
Posted by 구차니

먼가 쓸데없이 복잡해서 외우고 쓰진 못할 듯 -_ㅠ

import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)

[링크 : https://stackoverflow.com/questions/1987694/how-do-i-print-the-full-numpy-array-without-truncation]

'Programming > python(파이썬)' 카테고리의 다른 글

matplotlib animation  (0) 2024.02.28
pip 패키지 관리  (0) 2024.02.27
matplotlib grayscale image to 3d graph  (0) 2024.02.22
python tcp 서버 예제  (0) 2024.01.22
파이썬 소켓 예제  (0) 2024.01.17
Posted by 구차니

matplotlib을 이용하여 lena를 3d로 그리는게 보이길래 해보려는데

아래와 같이 deprecated 경고만 발생해서 되는걸 못 찾다가

>>> ax = fig.gca(projection='3d')
<stdin>:1: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().

>>> ax= Axes3D(fig)
<stdin>:1: MatplotlibDeprecationWarning: Axes3D(fig) adding itself to the figure is deprecated since 3.4. Pass the keyword argument auto_add_to_figure=False and use fig.add_axes(ax) to suppress this warning. The default value of auto_add_to_figure will change to False in mpl3.5 and True values will no longer work in 3.6.  This is consistent with other Axes classes.

 

chatGPT에게 물어보니 아래와 같이 줘서 시도하니 나오긴 나온다.

import cv2
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 이미지 읽기
image_path = 't.png'
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# 이미지의 높이와 너비 얻기
height, width = img.shape

# 2D 배열을 생성하여 각 픽셀의 깊이 값을 저장
depth_map = np.zeros_like(img, dtype=np.float32)

# 각 픽셀의 깊이 계산 (여기서는 그레이스케일 값으로 대체)
depth_map = img.astype(np.float32)

# 3D 그래프 생성
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# X, Y 좌표 생성
x = np.arange(0, width, 1)
y = np.arange(0, height, 1)
x, y = np.meshgrid(x, y)

# 깊이 맵을 사용하여 Z 좌표 생성
z = depth_map

# 3D 그래프에 표시
ax.plot_surface(x, y, z, cmap='viridis')

# 그래프 표시
plt.show()

 

분위기를 보아하니 viridis 를 해서 저런 녹색톤이 나오는것 같은데 plasms가 웬지 flir에서 보던 느런 느낌이려나?

[링크 : https://matplotlib.org/stable/users/explain/colors/colormaps.html]

 

 

위에서 보면 아래와 같이 lena 이미지가 똭!

[링크 : https://stackoverflow.com/questions/31805560/how-to-create-surface-plot-from-greyscale-image-with-matplotlib]

[링크 : https://jehyunlee.github.io/2021/07/10/Python-DS-80-mpl3d2/]

 

 

'Programming > python(파이썬)' 카테고리의 다른 글

pip 패키지 관리  (0) 2024.02.27
pyhthon numpy 생략없이 출력  (0) 2024.02.26
python tcp 서버 예제  (0) 2024.01.22
파이썬 소켓 예제  (0) 2024.01.17
ipython notebook -> jupyter notebook  (0) 2024.01.11
Posted by 구차니

예제를 복붙하고 nc 를 통해 테스트 하는데

nc 접속이 끊어지니  쓰레드에서 수신했다고 무한으로 뜬다.

접속하고 받는건 되지만, 끊어지는건 처리가 안된 예제..

 

[링크 : https://mogoh-developer.tistory.com/9]

[링크 : https://nalara12200.tistory.com/153]

[링크 : https://github.com/levhyun/python_socket]

 

+

2024.01.23

[링크 : https://codezaram.tistory.com/31]

'Programming > python(파이썬)' 카테고리의 다른 글

pyhthon numpy 생략없이 출력  (0) 2024.02.26
matplotlib grayscale image to 3d graph  (0) 2024.02.22
파이썬 소켓 예제  (0) 2024.01.17
ipython notebook -> jupyter notebook  (0) 2024.01.11
파이썬 가상환경  (0) 2024.01.09
Posted by 구차니

 

블러킹 방식이지만 잘 되긴 함.

[링크 : https://1d1cblog.tistory.com/69

 

그래서 멀티쓰레드로 작동하게 해야하나? 고민중

[링크 : https://m.blog.naver.com/jkg57/222480924841]

[링크 : https://nachwon.github.io/asyncio-futures/]

 

[링크 : https://orashelter.tistory.com/47]

[링크 : https://docs.python.org/3.6/library/asyncio-protocol.html]

'Programming > python(파이썬)' 카테고리의 다른 글

matplotlib grayscale image to 3d graph  (0) 2024.02.22
python tcp 서버 예제  (0) 2024.01.22
ipython notebook -> jupyter notebook  (0) 2024.01.11
파이썬 가상환경  (0) 2024.01.09
pyplot legend picking  (0) 2023.10.05
Posted by 구차니

interactive python 해서 ipython인가?

notebook은 ipython 꺼였는데 jupyter의 일부가 되었다고 한다.

Installing IPython

There are multiple ways of installing IPython. This page contains simplified installation instructions that should work for most users. Our official documentation contains more detailed instructions for manual installation targeted at advanced users and developers.
If you are looking for installation documentation for the notebook and/or qtconsole, those are now part of Jupyter.

[링크 : https://ipython.org/install.html]

[링크 : https://pypi.org/project/ipython/]

[링크 : https://yujuwon.tistory.com/m/entry/ipython-노트북-설치하기]

'Programming > python(파이썬)' 카테고리의 다른 글

python tcp 서버 예제  (0) 2024.01.22
파이썬 소켓 예제  (0) 2024.01.17
파이썬 가상환경  (0) 2024.01.09
pyplot legend picking  (0) 2023.10.05
matplotlib  (0) 2023.10.04
Posted by 구차니

이것저것 조사해보는데

무식하지만 가장 확실한(?) docker로 버전별로 혹은 프로젝트 별로 생성하는 것부터

python 에서 제공하는 venv

venv를 확장해서 사용하는 virtualenv

그리고 conda 정도로 정리되는 듯.

 

 

conda

[링크 : https://m.blog.naver.com/jonghong0316/221683053696]

 

virtualenv, venv

[링크 : https://jaemunbro.medium.com/python-virtualenv-venv-설정-aaf0e7c2d24e]

 

conda, venv

[링크 : https://yongeekd01.tistory.com/39]

 

venv, pipenv, conda, docker(이걸.. 가상이라고 하긴 해야 하는데.. 해줘야 하는거 맞....나?)

[링크 : https://dining-developer.tistory.com/21]

 

virtualenv, pyenv, pipenv

[링크 : https://jinwoo1990.github.io/dev-wiki/python-concept-3/]

 

+

conda - Conda provides package, dependency, and environment management for any language.

파이썬 전용이 아닌가?

[링크 : https://docs.conda.io/en/latest/]

[링크 : https://anaconda.org/]

[링크 : https://anaconda.org/anaconda/conda]

 

+

virtualenv

is slower (by not having the app-data seed method),
is not as extendable,
cannot create virtual environments for arbitrarily installed python versions (and automatically discover these),
is not upgrade-able via pip,
does not have as rich programmatic API (describe virtual environments without creating them).

[링크 : https://virtualenv.pypa.io/en/latest/]

 

+

venv

[링크 : https://docs.python.org/3/library/venv.html] 3.12.1

 

venv는 3.7 이후부터 사용이 가능한 것으로 보임. 즉, 버전별로 호환성은 없을 가능성이 있음

pyvenv 스크립트는 파이썬 3.6 에서 폐지되었고, 가상 환경이 어떤 파이썬 인터프리터를 기반으로 하는지에 대한 잠재적인 혼동을 방지하기 위해 python3 -m venv를 사용합니다.

[링크 : https://docs.python.org/ko/3.7/library/venv.html]

'Programming > python(파이썬)' 카테고리의 다른 글

파이썬 소켓 예제  (0) 2024.01.17
ipython notebook -> jupyter notebook  (0) 2024.01.11
pyplot legend picking  (0) 2023.10.05
matplotlib  (0) 2023.10.04
pyplot  (0) 2023.10.04
Posted by 구차니