'전체 글'에 해당되는 글 132건

Multiprocessing Python

Posted by PeEn
2019. 12. 28. 21:14 Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import multiprocessing
       
if __name__ == '__main__' :
    변수명 = multiprocessing.Process(target=함수, args=())
    
    변수명.start()

 

'Programing > Raspberry Pi)' 카테고리의 다른 글

Project2020  (0) 2020.03.09
Database Insert Python  (0) 2019.12.28
Buzzer Python  (0) 2019.12.28
Ultra(초음파) Python  (0) 2019.12.28
LED Python  (0) 2019.12.28

Database Insert Python

Posted by PeEn
2019. 12. 28. 21:11 Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import pymysql
import time
import datetime

#글로벌변수설정
nowdate = ""  # 날짜&시간
nowtime = ""  # 시간
startTime=''
endTime =''

# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)

def insertDB():
    conn = pymysql.connect(host='localhost', port=3306, user='id', passwd='passwd')
    sql = "INSERT INTO hackathon.datalist ( `filed1`, `filed2`, `filed3`, `filed4`, `filed5`, `filed6`)  VALUES(%s,%s,%s,%s,%s,%s);"
        
    cur = conn.cursor() 
    
    nowdate_f()
    global nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree
    val = (nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree)
    cur.execute(sql, val)
    
    conn.commit()
    cur.close()
    conn.close()



# 시간 함수__DEBTOLEE
def nowdate_f():
    # DATE
    global nowdate
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowdate = nowtemp.strftime('%Y-%m-%d')
    
def nowtime_f():
    global nowtime
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowtime = nowtemp.strftime('%H:%M')
    return nowtime

'Programing > Raspberry Pi)' 카테고리의 다른 글

Project2020  (0) 2020.03.09
Multiprocessing Python  (0) 2019.12.28
Buzzer Python  (0) 2019.12.28
Ultra(초음파) Python  (0) 2019.12.28
LED Python  (0) 2019.12.28

Buzzer Python

Posted by PeEn
2019. 12. 28. 21:08 Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time

BUZZER = 7

# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(BUZZER, gpio.OUT)

while True :
    GPIO.output(22,GPIO.HIGH)
    sleep(.1)
    GPIO.output(22,GPIO.LOW)
    sleep(.1)

'Programing > Raspberry Pi)' 카테고리의 다른 글

Multiprocessing Python  (0) 2019.12.28
Database Insert Python  (0) 2019.12.28
Ultra(초음파) Python  (0) 2019.12.28
LED Python  (0) 2019.12.28
해커톤 2019 113조 서버  (0) 2019.12.27

Servo Motor Python

Posted by PeEn
2019. 12. 28. 21:00 카테고리 없음
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time

SERVO_SIG = 20 # Servo

# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(SERVO_SIG, gpio.OUT)

#서브모터 변수로 정의
pwm = gpio.PWM(SERVO_SIG, 50) #

#서브모터 연결
pwm.start(default_Servo/18.0+2) 

#서브모터 방향 전환
pwm.ChangeDutyCycle(0/18.0+2)

Button Python

Posted by PeEn
2019. 12. 28. 09:19 카테고리 없음
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time

switch = 17  # 버튼

# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)


def Switch():
	pwm.start(default_Servo/18.0+2)
    while True:
    	switch_temp = gpio.input(switch)
        if switch_temp == False :
        	실행문

Ultra(초음파) Python

Posted by PeEn
2019. 12. 28. 09:15 Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time

TRIGER = 12 #초음파 tring
ECHO = 16   #초음파 echo


# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(TRIGER, gpio.OUT)
gpio.setup(ECHO,gpio.IN)

#초음파 함수
def Ultra():
    global cnt_One, cnt_Tree, cnt_Two, dist1
    while True:
        gpio.output(TRIGER,gpio.LOW)
        time.sleep(0.1)
        gpio.output(TRIGER,gpio.HIGH)
        time.sleep(0.00002)
        gpio.output(TRIGER,gpio.LOW)
        
        while gpio.input(ECHO) == gpio.LOW:
            startTime = time.time()
            
        while gpio.input(ECHO) == gpio.HIGH:
            endTime = time.time()
          
        period = endTime - startTime
        dist1 = round(period * 1000000 / 58, 2)
        
        print('Dist1', dist1, 'cm')
        
 Ultra()
    

'Programing > Raspberry Pi)' 카테고리의 다른 글

Database Insert Python  (0) 2019.12.28
Buzzer Python  (0) 2019.12.28
LED Python  (0) 2019.12.28
해커톤 2019 113조 서버  (0) 2019.12.27
Raspberry Pi - OpenCV 설치  (0) 2019.12.23

LED Python

Posted by PeEn
2019. 12. 28. 09:14 Programing/Raspberry Pi)
# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time

LED_1 = 27 # LED1

# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(LED_1, gpio.OUT)

def LoopLED():
	gpio.output(LED_1, gpio.LOW)
	time.sleep(1)
	gpio.output(LED_1, gpio.HIGH)
	time.sleep(1)
    
LoopLED()

'Programing > Raspberry Pi)' 카테고리의 다른 글

Buzzer Python  (0) 2019.12.28
Ultra(초음파) Python  (0) 2019.12.28
해커톤 2019 113조 서버  (0) 2019.12.27
Raspberry Pi - OpenCV 설치  (0) 2019.12.23
TCP Rasspberry Pi Python and Android Client  (0) 2019.09.21

해커톤 2019 안드로이드

Posted by PeEn
2019. 12. 28. 00:26
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.

해커톤 2019 113조 서버

Posted by PeEn
2019. 12. 27. 18:45 Programing/Raspberry Pi)

# -*- coding: utf-8 -*- import RPi.GPIO as gpio import time import sys import warnings import threading warnings.filterwarnings('ignore') cnt_One = 0 #샴푸 내린 횟수 cnt_Two = 0 #린스 내린 횟수 cnt_Tree = 0 #바디 내린 횟수 LED_STAT = 0 #LED 기본값 default_Servo = 0 #서보모터 기본값 0 45 90 135 chang_Servo =5 #서보모터 변경값 # ___gpio 핀번호___# switch = 17 # 버튼 LED_1 = 27 # LED1 LED_2 = 19 # LED2 LED_3 = 4 # LED3 LED_4 = 9 #LED4 초음파 대응센서 SERVO_SIG = 20 # Servo TRIGER = 12 #초음파 tring ECHO = 16 #초음파 echo # ____gipo 핀 세팅___# gpio.cleanup() gpio.setmode(gpio.BCM) gpio.setup(switch, gpio.IN) gpio.setup(LED_1, gpio.OUT) gpio.setup(LED_2, gpio.OUT) gpio.setup(LED_3, gpio.OUT) gpio.setup(LED_4, gpio.OUT) gpio.output(LED_1, gpio.LOW) gpio.output(LED_2, gpio.LOW) gpio.output(LED_3, gpio.LOW) gpio.output(LED_4, gpio.LOW) gpio.setup(TRIGER, gpio.OUT) gpio.setup(ECHO,gpio.IN) gpio.setup(SERVO_SIG, gpio.OUT) pwm = gpio.PWM(SERVO_SIG, 50) startTime = time.time() def Ultra(): global cnt_One, cnt_Tree, cnt_Two while True: gpio.output(TRIGER,gpio.LOW) time.sleep(0.1) gpio.output(TRIGER,gpio.HIGH) time.sleep(0.00002) gpio.output(TRIGER,gpio.LOW) while gpio.input(ECHO) == gpio.LOW: startTime = time.time() while gpio.input(ECHO) == gpio.HIGH: endTime = time.time() period = endTime - startTime dist1 = round(period * 1000000 / 58, 2) dist2 = round(period * 17241, 2) #print('Dist1', dist1, 'cm', ', Dist2', dist2, 'cm') if dist1<=13: gpio.output(LED_4, gpio.HIGH) if LED_STAT == 1: temp = int(cnt_One) cnt_One = temp+1 if LED_STAT == 2: temp = int(cnt_Two) cnt_Two = temp+1 if LED_STAT == 3: temp = int(cnt_Tree) cnt_Tree = temp+1 #print("13이하") else: gpio.output(LED_4, gpio.LOW) #print("13이상") def Switch(): gpio.output(LED_1, gpio.LOW) gpio.output(LED_2, gpio.LOW) gpio.output(LED_3, gpio.LOW) pwm.start(default_Servo/18.0+2) while True: switch_temp = gpio.input(switch) if switch_temp == False : global LED_STAT if LED_STAT == 0: LED_STAT =1 if LED_STAT == 4: LED_STAT =0 if LED_STAT==0: pwm.ChangeDutyCycle(0/18.0+2) gpio.output(LED_1, gpio.LOW) gpio.output(LED_2, gpio.LOW) gpio.output(LED_3, gpio.LOW) if LED_STAT==1: pwm.ChangeDutyCycle(45/18.0+2) gpio.output(LED_1, gpio.HIGH) gpio.output(LED_2, gpio.LOW) gpio.output(LED_3, gpio.LOW) if LED_STAT==2: pwm.ChangeDutyCycle(90/18.0+2) gpio.output(LED_1, gpio.LOW) gpio.output(LED_2, gpio.HIGH) gpio.output(LED_3, gpio.LOW) if LED_STAT==3: pwm.ChangeDutyCycle(135/18.0+2) gpio.output(LED_1, gpio.LOW) gpio.output(LED_2, gpio.LOW) gpio.output(LED_3, gpio.HIGH) print(LED_STAT) LED_STAT = LED_STAT + 1 time.sleep(2) if __name__ == '__main__' : thread_SWITCH = threading.Thread(target=Switch, args=()) thread_ULTRA = threading.Thread(target=Ultra, args=()) thread_SWITCH.start() thread_ULTRA.start()

# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time
import datetime
import sys
import warnings
import threading
import pymysql
warnings.filterwarnings('ignore')
nowdate = ""  # 날짜&시간
nowtime = ""  # 시간
cnt_One = 0 #샴푸 내린 횟수
cnt_Two = 0 #린스 내린 횟수
cnt_Tree = 0 #바디 내린 횟수
count=0 # 타이머 초
startTime=''
endTime =''

LED_STAT = 0 #LED 기본값
default_Servo = 0 #서보모터 기본값 0 45 90 135
chang_Servo =5 #서보모터 변경값
# ___gpio 핀번호___#

switch = 17  # 버튼
LED_1 = 27 # LED1
LED_2 = 19  # LED2
LED_3 = 4  # LED3
LED_4 = 9 #LED4 초음파 대응센서
SERVO_SIG = 20 # Servo
TRIGER = 12 #초음파 tring
ECHO = 16   #초음파 echo
BUZZER = 7


# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(switch, gpio.IN)

gpio.setup(BUZZER, gpio.OUT)

gpio.setup(LED_1, gpio.OUT)
gpio.setup(LED_2, gpio.OUT)
gpio.setup(LED_3, gpio.OUT)
gpio.setup(LED_4, gpio.OUT)
gpio.output(LED_1, gpio.LOW)
gpio.output(LED_2, gpio.LOW)
gpio.output(LED_3, gpio.LOW)
gpio.output(LED_4, gpio.LOW)

gpio.setup(TRIGER, gpio.OUT)
gpio.setup(ECHO,gpio.IN)


gpio.setup(SERVO_SIG, gpio.OUT)
pwm = gpio.PWM(SERVO_SIG, 50)



# 시간 함수__DEBTOLEE
def nowdate_f():
    # DATE
    global nowdate
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowdate = nowtemp.strftime('%Y-%m-%d')
    
def nowtime_f():
    global nowtime
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowtime = nowtemp.strftime('%H:%M')
    return nowtime

#초음파 함수
def Ultra():
    global cnt_One, cnt_Tree, cnt_Two
    while True:
        gpio.output(TRIGER,gpio.LOW)
        time.sleep(0.1)
        gpio.output(TRIGER,gpio.HIGH)
        time.sleep(0.00002)
        gpio.output(TRIGER,gpio.LOW)
        
        while gpio.input(ECHO) == gpio.LOW:
            startTime = time.time()
            
        while gpio.input(ECHO) == gpio.HIGH:
            endTime = time.time()
          
        period = endTime - startTime
        dist1 = round(period * 1000000 / 58, 2)
        dist2 = round(period * 17241, 2)
        
        #print('Dist1', dist1, 'cm', ', Dist2', dist2, 'cm')
        if dist1<=13:
            gpio.output(LED_4, gpio.HIGH)
            if LED_STAT == 1:
                temp = int(cnt_One)
                cnt_One = temp+1
            if LED_STAT == 2:
                temp = int(cnt_Two)
                cnt_Two = temp+1
            if LED_STAT == 3:
                temp = int(cnt_Tree) 
                cnt_Tree = temp+1
            
            #print("13이하")
        else:
            gpio.output(LED_4, gpio.LOW)
            #print("13이상")
        
            
def Switch():
    gpio.output(LED_1, gpio.LOW)
    gpio.output(LED_2, gpio.LOW)
    gpio.output(LED_3, gpio.LOW)
    
    pwm.start(default_Servo/18.0+2)
    global cnt_One,cnt_Two,cnt_Tree
    while True:
        switch_temp = gpio.input(switch)
        if switch_temp == False :
            global LED_STAT, startTime, endTime
            if LED_STAT == 0:
                thread_TIMER.start()
                startTime = nowtime_f()
                LED_STAT =1
            if LED_STAT == 4:
                count = -1
                LED_STAT =0
    
            if LED_STAT==0:
                pwm.ChangeDutyCycle(0/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.LOW)
                endTime = nowtime_f()
                insertDB()
                
    
            if LED_STAT==1:
                pwm.ChangeDutyCycle(45/18.0+2)
                gpio.output(LED_1, gpio.HIGH)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.LOW)
                cnt_One+=1
                
            if LED_STAT==2:
                pwm.ChangeDutyCycle(90/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.HIGH)
                gpio.output(LED_3, gpio.LOW)
                cnt_Two+=1;
                
            if LED_STAT==3:
                pwm.ChangeDutyCycle(135/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.HIGH)
                cnt_Tree+=1
                
            print(LED_STAT)
            LED_STAT = LED_STAT + 1
            time.sleep(2)

def w_timer():
    global count
    count+=1
    timer=threading.Timer(1,w_timer)
    timer.start()
    print(count)
    if count==6 :
        thread_BUZZER.start()
    
    if count==-1 :
        timer.cancel()
cntt = 0
def Buzzer_Th():
    global cntt
    while True:
        cntt +=1
        gpio.output(BUZZER, gpio.HIGH)
        time.sleep(1)
        gpio.output(BUZZER, gpio.LOW)
        time.sleep(1)    
        if cntt == 6 :
            thread_BUZZER.cancel()

def insertDB():
    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='8659')
    sql = "INSERT INTO hackathon.datalist ( `h_date`, `s_time`, `e_time`, `one_cnt`, `two_cnt`, `tree_cnt`)  VALUES(%s,%s,%s,%s,%s,%s);"
        
    cur = conn.cursor() 
    
    nowdate_f()
    global nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree
    val = (nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree)
    cur.execute(sql, val)
    conn.commit()
    cur.close()
    conn.close()

        
if __name__ == '__main__' :
    thread_TIMER = threading.Thread(target=w_timer, args=())
    thread_BUZZER = threading.Thread(target=Buzzer_Th, args=())
    thread_SWITCH = threading.Thread(target=Switch, args=())
    thread_ULTRA = threading.Thread(target=Ultra, args=())

    insertDB
  
    thread_SWITCH.start()
    thread_ULTRA.start()

# -*- coding: utf-8 -*-
import RPi.GPIO as gpio
import time
import datetime
import sys
import warnings
import threading
import multiprocessing
import pymysql
warnings.filterwarnings('ignore')
nowdate = ""  # 날짜&시간
nowtime = ""  # 시간
cnt_One = 0 #샴푸 내린 횟수
cnt_Two = 0 #린스 내린 횟수
cnt_Tree = 0 #바디 내린 횟수
count=0 # 타이머 초
dist1 = 0 #초음파 값
startTime=''
endTime =''

LED_STAT = 0 #LED 기본값
default_Servo = 0 #서보모터 기본값 0 45 90 135
chang_Servo =5 #서보모터 변경값
# ___gpio 핀번호___#

switch = 17  # 버튼
LED_1 = 27 # LED1
LED_2 = 19  # LED2
LED_3 = 4  # LED3
LED_4 = 9 #LED4 초음파 대응센서
SERVO_SIG = 20 # Servo
TRIGER = 12 #초음파 tring
ECHO = 16   #초음파 echo
BUZZER = 7


# ____gipo 핀 세팅___#
gpio.cleanup()
gpio.setmode(gpio.BCM)
gpio.setup(switch, gpio.IN)

gpio.setup(BUZZER, gpio.OUT)

gpio.setup(LED_1, gpio.OUT)
gpio.setup(LED_2, gpio.OUT)
gpio.setup(LED_3, gpio.OUT)
gpio.setup(LED_4, gpio.OUT)
gpio.output(LED_1, gpio.LOW)
gpio.output(LED_2, gpio.LOW)
gpio.output(LED_3, gpio.LOW)
gpio.output(LED_4, gpio.LOW)

gpio.setup(TRIGER, gpio.OUT)
gpio.setup(ECHO,gpio.IN)


gpio.setup(SERVO_SIG, gpio.OUT)
pwm = gpio.PWM(SERVO_SIG, 50)



# 시간 함수__DEBTOLEE
def nowdate_f():
    # DATE
    global nowdate
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowdate = nowtemp.strftime('%Y-%m-%d')
    
def nowtime_f():
    global nowtime
    nowtemp = ''
    nowtemp = datetime.datetime.now()
    nowtime = nowtemp.strftime('%H:%M')
    return nowtime

#초음파 함수
def Ultra():
    global cnt_One, cnt_Tree, cnt_Two, dist1
    while True:
        gpio.output(TRIGER,gpio.LOW)
        time.sleep(0.1)
        gpio.output(TRIGER,gpio.HIGH)
        time.sleep(0.00002)
        gpio.output(TRIGER,gpio.LOW)
        
        while gpio.input(ECHO) == gpio.LOW:
            startTime = time.time()
            
        while gpio.input(ECHO) == gpio.HIGH:
            endTime = time.time()
          
        period = endTime - startTime
        dist1 = round(period * 1000000 / 58, 2)
        
        print('Dist1', dist1, 'cm')
    
        if dist1<=13:
            gpio.output(LED_4, gpio.HIGH)
            if LED_STAT == 1:
                temp = int(cnt_One)
                cnt_One = temp+1
            if LED_STAT == 2:
                temp = int(cnt_Two)
                cnt_Two = temp+1
            if LED_STAT == 3:
                temp = int(cnt_Tree) 
                cnt_Tree = temp+1
            
            #print("13이하")
        else:
            gpio.output(LED_4, gpio.LOW)
            #print("13이상")

        
def Switch():
    gpio.output(LED_1, gpio.LOW)
    gpio.output(LED_2, gpio.LOW)
    gpio.output(LED_3, gpio.LOW)
    
    pwm.start(default_Servo/18.0+2)
    global cnt_One,cnt_Two,cnt_Tree
    while True:
        switch_temp = gpio.input(switch)
        if switch_temp == False :
            global LED_STAT, startTime, endTime
            if LED_STAT == 0:
                startTime = nowtime_f()
                LED_STAT =1


            if LED_STAT == 4:
                count = -1
                LED_STAT =0

            if LED_STAT==0:
                pwm.ChangeDutyCycle(0/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.LOW)
                endTime = nowtime_f()
                insertDB()
                count = -1
                
    
            if LED_STAT==1:
                pwm.ChangeDutyCycle(45/18.0+2)
                gpio.output(LED_1, gpio.HIGH)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.LOW)
                cnt_One+=1
                startTime = nowtime_f()
                
                
            if LED_STAT==2:
                pwm.ChangeDutyCycle(90/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.HIGH)
                gpio.output(LED_3, gpio.LOW)
                cnt_Two+=1;
                
            if LED_STAT==3:
                pwm.ChangeDutyCycle(135/18.0+2)
                gpio.output(LED_1, gpio.LOW)
                gpio.output(LED_2, gpio.LOW)
                gpio.output(LED_3, gpio.HIGH)
                cnt_Tree+=1
                
            print(LED_STAT)
            LED_STAT = LED_STAT + 1
            time.sleep(2)



def insertDB():
    conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='8659')
    sql = "INSERT INTO hackathon.datalist ( `h_date`, `s_time`, `e_time`, `one_cnt`, `two_cnt`, `tree_cnt`)  VALUES(%s,%s,%s,%s,%s,%s);"
        
    cur = conn.cursor() 
    
    nowdate_f()
    global nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree
    val = (nowdate,startTime,endTime,cnt_One,cnt_Two,cnt_Tree)
    cur.execute(sql, val)
    

    
    conn.commit()
    

    cur.close()
    conn.close()

        
if __name__ == '__main__' :
    thread_SWITCH = multiprocessing.Process(target=Switch, args=())
    thread_ULTRA = multiprocessing.Process(target=Ultra, args=())
    
    thread_SWITCH.start()
    thread_ULTRA.start()

'Programing > Raspberry Pi)' 카테고리의 다른 글

Ultra(초음파) Python  (0) 2019.12.28
LED Python  (0) 2019.12.28
Raspberry Pi - OpenCV 설치  (0) 2019.12.23
TCP Rasspberry Pi Python and Android Client  (0) 2019.09.21
라즈베리파이, LED와 초음파센서 DB저장  (0) 2019.09.07

Raspberry Pi - OpenCV 설치

Posted by PeEn
2019. 12. 23. 17:38 Programing/Raspberry Pi)

APT로 Python OpenCV 설치
sudo apt-get update
sudo apt-get install python-opencv  

빌드 설치
sudo apt-get install -y build-essen sudo apt-get install -y build-essential cmake pkg-config 
sudo apt-get install -y qtbase5-dev qtdeclarative5-dev

이미지 라이브러리 설치
sudo apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

비디오 라이브러리 설치
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev

디바이스 라이브러리 설치
sudo apt-get install -y libv4l-dev v4l-utils

비디오 스트림 라이브러리 설치
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

GUI 윈도라이브러리 설치
sudo apt-get install -y libqt4-dev

OpenGL 라이브러리 설치
sudo apt-get install -y mesa-utils libgl1-mesa-dri libqt4-opengl-dev libatlas-base-dev gfortran libeigen3-dev

파이썬 빌드 관련 라이브러리 설치
sudo apt-get install -y python-dev python3-dev

OpenCV 폴더 생성
mkdir opencv
cd opencv

코드 다운
https://github.com/opencv/opencv/releases

 

opencv/opencv

Open Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub.

github.com

https://github.com/opencv/opencv_contrib/releases

 

opencv/opencv_contrib

Repository for OpenCV's extra modules. Contribute to opencv/opencv_contrib development by creating an account on GitHub.

github.com

두 사이트에서 tar.gz 링크 복사 해서 아래 코드에 적용해서 다운&압축해제

wget -O opencv-4.2.0.tar.gz https://github.com/opencv/opencv/archive/4.2.0.tar.gz

wget -O opencv_contrib-4.2.0.tar.gz https://github.com/opencv/opencv_contrib/archive/4.2.0.tar.gz

tar zxvf opencv-4.2.0.tar.gz

tartar zxvf opencv_contrib-4.2.0.tar.gz

mkdir ./opencv-4.2.0/build
cd ./opencv-4.2.0/build/

cmake 명령어로 빌드 작업
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.2.0/modules \
-D BUILD_DOCS=ON \
-D BUILD_EXAMPLES=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_XINE=ON ../

이후 시간이 조금 지나면 설정이 자동으로 진행된다.
그리고 성공적으로 적요이 되면 아래 같이 출력된다.

-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/opencv/opencv-4.2.0/build

오류날때 아래 접어논 글처럼 시도

더보기

cd $HOME
wget http://www.cmake.org/files/v3.9/cmake-3.9.6.tar.gz
tar xvfz cmake-3.9.6.tar.gz
cd cmake-3.9.6 ./configure
--prefix=$HOME/software
make
make install
설치진행

make -j3

sudo make install

제대로 설치되었다면

cat /etc/ld.so.conf.d/* 을 입력 시 아래와 같이 출력된다

더보기


pi@raspberrypi:~/opencv/opencv-4.1.2/build $ cat /etc/ld.so.conf.d/*
/opt/vc/lib
# Multiarch support
/usr/local/lib/arm-linux-gnueabihf
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf/libfakeroot
# libc default configuration
/usr/local/lib