반응형

Program made with Python and Pygame module for visualizing sorting algorithms

Support this project by leaving a ⭐

 

  • Run: python3 src/main.py

https://github.com/LucasPilla/Sorting-Algorithms-Visualizer/tree/master

 

GitHub - LucasPilla/Sorting-Algorithms-Visualizer: Program made with Python and Pygame module for visualizing sorting algorithms

Program made with Python and Pygame module for visualizing sorting algorithms - GitHub - LucasPilla/Sorting-Algorithms-Visualizer: Program made with Python and Pygame module for visualizing sorting...

github.com

반응형
반응형

[python] Use Phone Camera with python 

 

https://thecleverprogrammer.com/2021/01/05/use-phone-camera-with-python/

 

Use Phone Camera with Python | Aman Kharwal

In this article, I will walk you through how to use your phone camera with Python for computer vision. Use the Phone Camera with Python.

thecleverprogrammer.com

install CV : https://pypi.org/project/opencv-python/  

""" https://thecleverprogrammer.com/2021/01/05/use-phone-camera-with-python/

    https://pypi.org/project/opencv-python/
    > pip install opencv-python
    > pip install opencv-contrib-python
"""
import cv2
import numpy as np

url = "Your IP Address/video"

cap = cv2.VideoCapture(url)

while(True):
    camera, frame = cap.read()
    if frame is not None:
        cv2.imshow("Frame", frame)
    q = cv2.waitKey(1)
    if q==ord("q"):
        break

cv2.destroyAllWindows()

 

https://stackoverflow.com/questions/50185654/opencv-load-video-from-url

 

OpenCV load video from url

I have a video file (i.e. https://www.example.com/myvideo.mp4) and need to load it with OpenCV. Doing the equivalent with an image is fairly trivial: imgReq = requests.get("https://www.example.com/

stackoverflow.com

 

 

 

반응형
반응형

Google 지도 서비스용 Python 클라이언트

파이썬을 사용합니까? 무언가를 지오코딩하고 싶습니까? 방향을 찾고 계십니까? 아마도 방향의 행렬일까요? 이 라이브러리는 Google Maps Platform 웹 서비스를 Python 애플리케이션에 제공합니다.

Google Maps Services용 Python 클라이언트는 다음 Google Maps API용 Python 클라이언트 라이브러리입니다.

  • 길찾기 API
  • 거리 행렬 API
  • 고도 API
  • 지오코딩 API
  • 지리적 위치 API
  • 시간대 API
  • 도로 API
  • 장소 API
  • 지도 정적 API
  • 주소 확인 API

 

요구 사항

  • 파이썬 3.5 이상.
  • Google 지도 API 키입니다.

API 키

각 Google 지도 웹 서비스 요청에는 API 키 또는 클라이언트 ID가 필요합니다. API 키는 Google Cloud Console 'API 및 서비스' 탭의 '사용자 인증 정보' 페이지에서 생성됩니다 .

Google Maps Platform 시작하기 및 API 키 생성/제한에 대한 자세한 내용은 Google 문서에서 Google Maps Platform 시작하기를 참조하세요.

중요: 이 키는 서버에서 비밀로 유지되어야 합니다.

설치

$ pip install -U googlemaps

연결/읽기 제한 시간을 지정하려면 요청 2.4.0 이상이 필요합니다.

 

 

https://pypi.org/project/googlemaps/

 

googlemaps

Python client library for Google Maps Platform

pypi.org

 

https://github.com/googlemaps/google-maps-services-python

 

GitHub - googlemaps/google-maps-services-python: Python client library for Google Maps API Web Services

Python client library for Google Maps API Web Services - GitHub - googlemaps/google-maps-services-python: Python client library for Google Maps API Web Services

github.com

 

반응형
반응형

파이썬 컴파일 위치에 따라 import에 이슈가 발생하곤 한다. 

파일 실행시 이미지가 상대경로라면

프로그램 파일 상단에 작업디렉토리 변경을 통해서 현재 파일의 이슈를 줄일 수 있다. 

 

1.현재 파일의 이름 & 경로

import os

#현재 파일 이름
print(__file__)

#현재 파일 실제 경로
print(os.path.realpath(__file__))

#현재 파일 절대 경로
print(os.path.abspath(__file__))

2.현재 파일의 디렉토리 경로

import os

#현재 폴더 경로; 작업 폴더 기준
print(os.getcwd())

#현재 파일의 폴더 경로; 작업 파일 기준
print(os.path.dirname(os.path.realpath(__file__)))

3.현재 디렉토리의 파일 리스트

import os
print(os.listdir(os.getcwd()))

4.작업 디렉토리 변경

import os
os.chdir("/home/dada/test/")
반응형
반응형

python에서 pygame 실행해보기 aliens  https://www.pygame.org/wiki/GettingStarted

 

anaconda 설치하고 가상환경 들어가서 파이썬 버전(3.10 이상) 확인하고 

pygame 인스톨 후 실행. 

-- pygame 외계인 게임실행하기 

anaconda shell에서 

> pip install -U pygame

> python -m pygame.examples.aliens

https://www.pygame.org/wiki/GettingStarted

(p_pygame) PS D:\_py_project\> conda deactivate
(base) PS D:\_py_project\> conda activate p_pygame
(p_pygame) PS D:\_py_project\> pip install -U pygame
Requirement already satisfied: pygame in c:\programdata\anaconda3\envs\p_pygame\lib\site-packages (2.4.0)
(p_pygame) PS D:\_py_project\> python -m pygame.examples.aliens

반응형
반응형

https://sdc-james.gitbook.io/onebook/2./2.1./2.1.5.-visual-studio-code

 

3.1.5. Visual Studio Code 설치 - OneBook(Python & Deep Learning)

Visual Studio Code(약자 VS Code)는 편리한 프로그래밍 에디터 입니다. Visual Studio Code (VS Code)는 크로스 플랫폼 소스 편집기로서 윈도우즈, 리눅스, Mac OS 에서 무료로 사용할 수 있습다. Visual Studio Code를

sdc-james.gitbook.io

Visual Studio Code(약자 VS Code)는 편리한 프로그래밍 에디터 입니다. Visual Studio Code (VS Code)는 크로스 플랫폼 소스 편집기로서 윈도우즈, 리눅스, Mac OS 에서 무료로 사용할 수 있습다. Visual Studio Code를 설치한 후 여러 Extension들을 설치할 수 있는데, 파이썬 Extension을 설치하면, 파이썬 프로그래밍과 디버깅을 할 수 있습니다.
다음 링크에서 다운로드 할 수 있습니다.
User Installer는 현재 로그온된 사용자 계정에만 설치를 하며, System Installer는 Windows 전체 사용자 계정에서 사용할 수 있도록 설치(관리자 권한 필요)합니다. 저는 System Installer 버전을 다운로드하여 설치하겠습니다.
기본 옵션으로 설치를 끝까지 진행 합니다. 마지막에는 자신이 편리한대로 설정해 줍니다.
 
VSCode 가 설치 완료되면 필요한 Extension 들을 설치해 줍니다. Visual Studio Code를 설치한 후 여러 Extension들을 설치할 수 있는데, 파이썬 Extension을 설치하면, 파이썬 프로그래밍과 디버깅을 할 수 있습니다.
좌측 상단에 python을 입력하면 여러가지 Extension들이 나타납니다. 이중 Python Extension Pack 을 설치하면 Python, MagicPython, Visual Studio InteliCode, Django 등이 한꺼번에 설치됩니다. 이렇게 파이썬 Extension을 설치 완료하면 파이썬 프로그래밍을 진행할 수 있습니다. korean language pack 도 설치해 줍니다.
Pylance, Material Theme, Material Icon Theme, Prettier 등 필요한 Extension 들을 설치해 줍니다.
Pylance : Fast, feature-rich language support for Python
Prettier : 파일 저장시 알아서 포매쇼에 맞게 소스 코드 정
 
이제는 Visual Studio Code의 기본 터미널이 Windows의 Power Shell로 설정되어 있기 때문에 약간의 수정이 필요합니다.
이 기본 터미널의 종류를 cmd 또는 cmdGit Bash로 변경하면 오류없이 실행이 가능합니다. 먼저 Ctrl + Shift + P (컨트롤 + 쉬프트 + P) 키를 눌러 Command Palette를 열고 Terminal: Select Default Shell 을 입력합니다.
VS Code에서 파이썬 코드를 작성하기 위해서는 확장자 .py 를 가진 임의의 파이썬 파일을 생성하면 됩니다. [File] 메뉴에서 [New File]을 눌러 새 파일을 만들면 됩니다. 새 파일을 만드는 것보다 C:\ 에 'korAI'라는 새로운 작업 폴더를 만들어 줍니다.
이 작업 폴더에 새 hello.py 파일을 생성하고 에디터에서 코드를 작성합니다. 그리고 해당 폴더에 저장 합니다.
print("Hello World")
 
코드를 실행하기 전에 인터프리터를 선택해야 합니다. Ctrl + Shift + P (컨트롤 + 쉬프트 + P) 키를 눌러 Command Palette를 열고 Python: Select Interpreter 을 입력합니다.
여기에 가상 환경 설정에서 지정한 koreait 폴더내의 인터프리터를 지정합니다.
koreait 가상환경을 activate 합니다.
코드 작성 완료 후 프로그램을 실행하기 위해서는 [Debug] 메뉴의 [Start Debugging (F5)] 나 [Start without Debugging (Ctrl+F5)]를 누르면 됩니다.
특히 F5를 눌러 디버깅 모드로 실행하면, 로컬변수, 콜스택 등 여러 디버깅 정보를 이용할 수 있으며, Step Over, Step Into 등의 디버거 컨트롤을 사용할 수 있다.
파이썬 파일에 코드를 작성한 후, VS Code 에디터에서 우측 마우스 버튼을 클릭 [Run Python File in Terminal] 메뉴를 선택하면 하단에 터미날 창이 생기고 파이썬 프로그램을 인터프리터와 함께 실행해 준다.
 
VS Code 권장 Extension Pack
 
반응형
반응형

python, anaconda 가상환경에서 파이썬 버전 확인 및 변경

 

VScode에서 인터프리터 연결이 제대로 안될때. 버전이 낮아서 인터프리터 실행못할때 확인 필요

 

가상환경이름을 p_pygame  이라고 가정하고.

 

0. conda  activate (가상환경명) : 가상환경 실행.

1. python -V : 파이썬 버전 확인.

2. conda search python : 사용 가능한 python list 확인.

3. conda install python=x.x.x : 입력 버전으로 파이썬 버전이 변경됨.

4. conda deactivate

5. conda activate p_pygame   : 가상환경 실행.

6. python -V : 변경된 파이썬 버전을 확인할 수 있음.

반응형
반응형

 

아나콘다 다운로드 및 설치

 

가상환경 들어가서 pip update 필요하다. 

conda update pip

현재 (base) 환경에서 사용중인 파이썬 버전을 확인하려면 다음 명령을 실행합니다.

PIP는 Python Package Index (PyPI) 저장소로부터 패키지를 다운받아 설치 및 관리해주는 패키지 매니저 입니다. pip install [패키지 이름]의 형태로 패키지를 설치하면 됩니다.
Pip를 최신 버전으로 업그레이드 하려면 다음 명령을 실행합니다.
(base) PS D:\_py_project> python --version

(base) PS D:\_py_project> python -m pip install --upgrade pip

아나콘다 패키지 업데이트

(base) C:\Users\사용자계정>conda -–version

(base) C:\Users\사용자계정>conda update --all

 

pygame :  https://www.pygame.org/wiki/GettingStarted

 

GettingStarted - pygame wiki

Pygame Installation Pygame requires Python; if you don't already have it, you can download it from python.org. It's recommended to run the latest python version, because it's usually faster and has better features than the older ones. Bear in mind that pyg

www.pygame.org

 

아나콘다 설치 모르겠으면 기본 설치로~ https://docs.python.org/3/using/windows.html#installation-steps

 

4. Using Python on Windows

This document aims to give an overview of Windows-specific behaviour you should know about when using Python on Microsoft Windows. Unlike most Unix systems and services, Windows does not include a ...

docs.python.org

 

반응형

+ Recent posts