728x90

출처

WSL 머신 상태

PS C:\Users\bluesanta> wsl -l -v
  NAME              STATE           VERSION
* docker-desktop    Stopped         2
  Ubuntu            Running         2

WSL 머신 종료

PS C:\Users\bluesanta> wsl -t Ubuntu
작업을 완료했습니다.

WSL 머신 재설치

기존 설치된 머신 삭제

PS C:\Users\bluesanta> wsl --unregister Ubuntu
등록 취소 중입니다.
작업을 완료했습니다.
PS C:\Users\bluesanta> wsl -l -v
  NAME              STATE           VERSION
* docker-desktop    Stopped         2

WSL 배포판 확인

PS C:\Users\bluesanta> wsl -l -o
다음은 설치할 수 있는 유효한 배포판 목록입니다.
'wsl.exe --install '를 사용하여 설치합니다.

NAME                            FRIENDLY NAME
Ubuntu                          Ubuntu
Debian                          Debian GNU/Linux
kali-linux                      Kali Linux Rolling
Ubuntu-18.04                    Ubuntu 18.04 LTS
Ubuntu-20.04                    Ubuntu 20.04 LTS
Ubuntu-22.04                    Ubuntu 22.04 LTS
Ubuntu-24.04                    Ubuntu 24.04 LTS
OracleLinux_7_9                 Oracle Linux 7.9
OracleLinux_8_7                 Oracle Linux 8.7
OracleLinux_9_1                 Oracle Linux 9.1
openSUSE-Leap-15.6              openSUSE Leap 15.6
SUSE-Linux-Enterprise-15-SP5    SUSE Linux Enterprise 15 SP5
SUSE-Linux-Enterprise-15-SP6    SUSE Linux Enterprise 15 SP6
openSUSE-Tumbleweed             openSUSE Tumbleweed

WSL 리눅스 설치

PS C:\Users\bluesanta> wsl --install Ubuntu-22.04
설치 중: Ubuntu 22.04 LTS
Ubuntu 22.04 LTS이(가) 설치되었습니다.
Ubuntu 22.04 LTS을(를) 시작하는 중...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: bluesanta
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.
 
Welcome to Ubuntu 22.04.5 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
 
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro
 
 System information as of Sun Feb 16 15:54:18 KST 2025
 
  System load:  0.0                 Processes:             81
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 6%                  IPv4 address for eth0: 172.27.90.206
  Swap usage:   0%
 
 
This message is shown once a day. To disable it please create the
/home/bluesanta/.hushlogin file.
bluesanta@DESKTOP-2NKL9OB:~$

설치 확인

PS C:\Users\bluesanta> wsl -l -v
  NAME              STATE           VERSION
* docker-desktop    Running         2
  Ubuntu-22.04      Running         2

Python 3.11 설치

기존에 설치된 Python 설치 버전 확인

bluesanta@DESKTOP-2NKL9OB:~$ python3 --version
Python 3.10.12

기존에 설치된 Python 삭제

bluesanta@DESKTOP-2NKL9OB:~$ sudo apt remove python3
bluesanta@DESKTOP-2NKL9OB:~$ sudo apt autoremove

Python 3.11 빌드에 필요한 패키지 설치

bluesanta@DESKTOP-2NKL9OB:~$ sudo apt update
bluesanta@DESKTOP-2NKL9OB:~$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev pkg-config lzma liblzma-dev cmake build-essential libx11-dev libxext-dev libxft-dev libxss-dev libxrender-dev libfontconfig1-dev libxinerama-dev libxrandr-dev libxcursor-dev libminizip-dev libbz2-dev liblzma-dev libzstd-dev libssl-dev zip unzip

tcl8.6 설치

bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ tar xvf tcl8.6.16-src.tar.gz
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ cd tcl8.6.16/unix/
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tcl8.6.16/unix$ ./configure --prefix=/usr/local
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tcl9.0.1/unix$ make -j$(nproc)
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tcl9.0.1/unix$ sudo make install

tk8.6 설치

bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ tar xvf tk8.6.16-src.tar.gz
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ cd tk8.6.16/unix/
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tk8.6.16/unix$ ./configure --prefix=/usr/local --with-tcl=/usr/local/lib
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tk8.6.16/unix$ make -j$(nproc)
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama/tk8.6.16/unix$ sudo make install

Python 3.11 소스 다운로드

bluesanta@DESKTOP-2NKL9OB:~$ wget https://www.python.org/ftp/python/3.11.11/Python-3.11.11.tgz

Python 3.11 소스 압축풀기

bluesanta@DESKTOP-2NKL9OB:~$ tar -xf Python-3.11.11.tgz

configure 실행

bluesanta@DESKTOP-2NKL9OB:~$ cd Python-3.11.11
bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ export TCLTK_CFLAGS="-I/usr/local/include"
bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ export TCLTK_LIBS="-L/usr/local/lib -ltcl8.6 -ltk8.6"
bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ ./configure --enable-optimizations

Python 3.11 빌드

bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ grep -c processor /proc/cpuinfo
28
bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ make -j$(nproc)
bluesanta@DESKTOP-2NKL9OB:~/Python-3.11.11$ sudo make install

tkinter 확인

bluesanta@DESKTOP-PAV8U75:~/Python-3.11.11$ python3 -m tkinter

Python 3.11 설치 확인

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Users/bluesanta$ python3 --version
Python 3.11.11

pip 설치

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Users/bluesanta$ wget https://bootstrap.pypa.io/get-pip.py
bluesanta@DESKTOP-2NKL9OB:/mnt/c/Users/bluesanta$ python3 get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Downloading pip-25.0.1-py3-none-any.whl.metadata (3.7 kB)
Collecting wheel
  Downloading wheel-0.45.1-py3-none-any.whl.metadata (2.3 kB)
Downloading pip-25.0.1-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 708.7 kB/s eta 0:00:00
Downloading wheel-0.45.1-py3-none-any.whl (72 kB)
Installing collected packages: wheel, pip
  WARNING: The script wheel is installed in '/home/bluesanta/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pip, pip3 and pip3.11 are installed in '/home/bluesanta/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-25.0.1 wheel-0.45.1
 
[notice] A new release of pip is available: 24.0 -> 25.0.1
[notice] To update, run: pip3 install --upgrade pip
bluesanta@DESKTOP-2NKL9OB:/mnt/c/Users/bluesanta$ pip3 --version
pip 25.0.1 from /home/bluesanta/.local/lib/python3.11/site-packages/pip (python 3.11)

CUDA Toolkit & cuDNN 설치

CUDA Toolkit 12,1 설치

bluesanta@DESKTOP-2NKL9OB:~$ wget https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run
bluesanta@DESKTOP-2NKL9OB:~$ chmod +x cuda_12.1.0_530.30.02_linux.run
bluesanta@DESKTOP-2NKL9OB:~$ sudo sh cuda_12.1.0_530.30.02_linux.run --toolkit --silent --driver
bluesanta@DESKTOP-2NKL9OB:~$ ls /usr/local/ | grep cuda
cuda
cuda-12.1

CUDA Toolkit 11.8 설치

bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo dpkg -i cuda-repo-wsl-ubuntu-11-8-local_11.8.0-1_amd64.deb
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo cp /var/cuda-repo-wsl-ubuntu-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo apt update
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo apt -y install cuda
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ ls /usr/local/ | grep cuda
cuda
cuda-11
cuda-11.8

cuDNN 9.8 설치

bluesanta@DESKTOP-2NKL9OB:~$ wget https://developer.download.nvidia.com/compute/cudnn/9.8.0/local_installers/cudnn-local-repo-ubuntu2204-9.8.0_1.0-1_amd64.deb
bluesanta@DESKTOP-2NKL9OB:~$ sudo dpkg -i cudnn-local-repo-ubuntu2204-9.8.0_1.0-1_amd64.deb
bluesanta@DESKTOP-2NKL9OB:~$ sudo cp /var/cudnn-local-repo-ubuntu2204-9.8.0/cudnn-*-keyring.gpg /usr/share/keyrings/
bluesanta@DESKTOP-2NKL9OB:~$ sudo apt update
bluesanta@DESKTOP-2NKL9OB:~$ sudo apt-get -y install cudnn

cuDNN 8.6 설치

bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ tar -xvf cudnn-linux-x86_64-8.6.0.163_cuda11-archive.tar.xz
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo cp cudnn-linux-x86_64-8.6.0.163_cuda11-archive/include/cudnn*.h /usr/local/cuda-11.8/include
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo cp -P cudnn-linux-x86_64-8.6.0.163_cuda11-archive/lib/libcudnn* /usr/local/cuda-11.8/lib64
bluesanta@DESKTOP-PAV8U75:/mnt/c/Llama$ sudo chmod a+r /usr/local/cuda-11.8/lib64/libcudnn*

~/.bashrc 내용 추가

bluesanta@DESKTOP-2NKL9OB:~$ vi ~/.bashrc
export CUDA_PATH=/usr/local/cuda-12.1
export CUDA_HOME=/usr/local/cuda-12.1
export CUDADIR=/usr/local/cuda-12.1
export PATH=$PATH:$CUDADIR/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDADIR/lib64

# export CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
# export CUDNN_PATH=/mnt/c/Llama/.venv_wsl/lib/python3.11/site-packages/nvidia/cudnn
# export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH

# export HF_HOME=/mnt/c/Llama/huggingface

~/.bashrc 내용 추가

bluesanta@DESKTOP-2NKL9OB:~$ vi ~/.bashrc
export CUDA_PATH=/usr/local/cuda-11
export CUDA_HOME=/usr/local/cuda-11
export CUDADIR=/usr/local/cuda-11
export PATH=$PATH:$CUDADIR/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDADIR/lib64

# export CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
# export CUDNN_PATH=/mnt/c/Llama/.venv_wsl/lib/python3.11/site-packages/nvidia/cudnn
# export LD_LIBRARY_PATH=/usr/local/lib:$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH

export HF_HOME=/mnt/c/Llama/huggingface

CUDA Toolkit 설치 확인

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Users/bluesanta$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Tue_Feb__7_19:32:13_PST_2023
Cuda compilation tools, release 12.1, V12.1.66
Build cuda_12.1.r12.1/compiler.32415258_0

tensorflow gpu 설치

$ pip install tensorrt==8.6.1
$ pip install tensorflow[and-cuda]==2.15

faiss-gpu-cu12 설치

bluesanta@DESKTOP-2NKL9OB:~$ pip install faiss-gpu-cu12

ollama 설치

ollama 설치 스크립트 다운로드 및 설치

bluesanta@DESKTOP-2NKL9OB:~$ curl https://ollama.ai/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13269    0 13269    0     0  34377      0 --:--:-- --:--:-- --:--:-- 34375
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 bundle
######################################################################## 100.0%
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
>>> Nvidia GPU detected.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.

ollama 서비스 실행 확인

bluesanta@DESKTOP-2NKL9OB:~$ sudo systemctl status ollama.service
● ollama.service - Ollama Service
     Loaded: loaded (/etc/systemd/system/ollama.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2025-02-16 20:56:53 KST; 17s ago
   Main PID: 1766 (ollama)
      Tasks: 11 (limit: 9345)
     Memory: 38.8M
     CGroup: /system.slice/ollama.service
             └─1766 /usr/local/bin/ollama serve

Feb 16 20:56:53 DESKTOP-2NKL9OB systemd[1]: Started Ollama Service.
Feb 16 20:56:53 DESKTOP-2NKL9OB ollama[1766]: Couldn't find '/usr/share/ollama/.ollama/id_ed25519'. Generating new priv>

ollama 모델 경로 변경

ollama.service 내용 추가

bluesanta@DESKTOP-2NKL9OB:~$ sudo vi /etc/systemd/system/ollama.service
Environment="OLLAMA_MODELS=/mnt/c/Llama/Models/Ollama/models"

ollama 서비스 재실행

bluesanta@DESKTOP-2NKL9OB:~$ sudo systemctl daemon-reload
bluesanta@DESKTOP-2NKL9OB:~$ sudo systemctl restart ollama.service

Python 가상 환경 만들기

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ python3 -m venv .venv_wsl
bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ source .venv_wsl/bin/activate
(.venv_wsl) bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$

langserve_ollama 관련 패키지 설치

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ pip install fastapi uvicorn langchain_core langserve langchain_ollama langchain_text_splitters langchain_community sse_starlette pdfplumber faiss-gpu-cu12

huggingface-hub 패키지 설치

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ pip install huggingface-hub

ollama 모델 설치

bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ huggingface-cli download LGAI-EXAONE/EXAONE-3.5-7.8B-Instruct-GGUF EXAONE-3.5-7.8B-Instruct-BF16.gguf --local-dir /mnt/c/Llama/Models/Ollama/gguf --local-dir-use-symlinks False
(.venv_wsl) bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama$ cd Models/Ollama/gguf/
(.venv_wsl) bluesanta@DESKTOP-2NKL9OB:/mnt/c/Llama/Models/Ollama/gguf$ ollama create exaone -f EXAONE-3.5-7.8B-Instruct-BF16/Modelfile
728x90
728x90

출처

application.properties

#File upload settings
# support multipart uploads (default: true)
spring.servlet.multipart.enabled=true
# Threshold at which files are written to memory (default: 0B)
#spring.servlet.multipart.file-size-threshold=0B 
# Temporary storage space for uploaded files
spring.servlet.multipart.location=d:/usr/local/cnssm/resources
# Maximum size of the file (default: 1MB)
spring.servlet.multipart.max-file-size=10144MB
# Maximum size of request (default: 10MB)
spring.servlet.multipart.max-request-size=10144MB

FileStorageProperties.java

package com.bx.config.property;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "spring.servlet.multipart")
public class FileStorageProperties {

	private String location;

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}
}

FileUploadController.java

package com.bx.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.bx.common.util.ExcelUtil;
import com.bx.config.property.FileStorageProperties;
import com.bx.service.FileStorageService;

@Controller
public class FileUploadController {

	@Autowired
	private FileStorageService fileStorageService;

	@Autowired
	private FileStorageProperties fileStorageProperties;

	@RequestMapping(value = "/bx/uploadFile", method = RequestMethod.POST)
	public String uploadFile(@RequestParam("file") MultipartFile file, ModelMap modelMap) {
		String fileName = fileStorageService.storeFile(file);
		modelMap.put("fileName", fileName);
		
		try {
			if (fileName != null && (fileName.endsWith(".xls") || fileName.endsWith(".xlsx"))) {
				FileInputStream fis = new FileInputStream(new File(fileStorageProperties.getLocation() + "/" + fileName));
				Workbook workbook = new XSSFWorkbook(fis);
				
				Sheet sheet = workbook.getSheetAt(0); // 첫 번째 시트 가져오기
				
				// 행 반복 (첫 번째 행부터 마지막 행까지)
				for (Row row : sheet) {
					// 열 반복 (첫 번째 열부터 마지막 열까지)
					for (Cell cell : row) {
						// 셀 값 출력
						System.out.print(ExcelUtil.getCellValue(cell) + "\t");
					}
					System.out.println(); // 행 끝나면 줄바꿈
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return "bx/uploadOk";
	}

	@RequestMapping(value = "/uploadMultipleFiles", method = RequestMethod.POST)
	public String uploadMultipleFiles(@RequestParam("files") MultipartFile[] files, ModelMap modelMap) {
		Arrays.asList(files).stream().map(file -> uploadFile(file, modelMap)).collect(Collectors.toList());

		return "bx/uploadOk";
	}

}

FileStorageService.java

package com.bx.service;

import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import com.bx.common.exception.FileNotFoundException;
import com.bx.common.exception.FileStorageException;
import com.bx.config.property.FileStorageProperties;

@Service
public class FileStorageService {

	private final Path fileStorageLocation;

	@Autowired
	public FileStorageService(FileStorageProperties fileStorageProperties) {
		this.fileStorageLocation = Paths.get(fileStorageProperties.getLocation()).toAbsolutePath().normalize();

		try {
			Files.createDirectories(this.fileStorageLocation);
		} catch (Exception ex) {
			throw new FileStorageException("Could not create the directory where the uploaded files will be stored.", ex);
		}
	}

	public String storeFile(MultipartFile file) {
		// Normalize file name
		String fileName = StringUtils.cleanPath(file.getOriginalFilename());

		try {
			// Check if the file's name contains invalid characters
			if (fileName.contains("..")) {
				throw new FileStorageException("Sorry! Filename contains invalid path sequence " + fileName);
			}

			// Copy file to the target location (Replacing existing file with the same name)
			Path targetLocation = this.fileStorageLocation.resolve(fileName);
			Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);

			return fileName;
		} catch (IOException ex) {
			throw new FileStorageException("Could not store file " + fileName + ". Please try again!", ex);
		}
	}

	public Resource loadFileAsResource(String fileName) {
		try {
			Path filePath = this.fileStorageLocation.resolve(fileName).normalize();
			Resource resource = new UrlResource(filePath.toUri());
			if (resource.exists()) {
				return resource;
			} else {
				throw new FileNotFoundException("File not found " + fileName);
			}
		} catch (MalformedURLException ex) {
			throw new FileNotFoundException("File not found " + fileName, ex);
		}
	}
}

FileNotFoundException.java

package com.bx.common.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.NOT_FOUND)
public class FileNotFoundException extends RuntimeException {

	private static final long serialVersionUID = 1L;
	
	public FileNotFoundException(String message) {
		super(message);
	}
	
	public FileNotFoundException(String message, Throwable cause) {
		super(message, cause);
	}
}

FileStorageException.java

package com.bx.common.exception;

public class FileStorageException extends RuntimeException {
	
	private static final long serialVersionUID = 1L;

	public FileStorageException(String message) {
		super(message);
	}
	
	public FileStorageException(String message, Throwable cause) {
		super(message, cause);
	}
}

HTML

<form method="post" action="<c:url value="/cnssm/uploadFile"/>" enctype="multipart/form-data">

  <div>
    file : <input type="file" name="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
  </div>
  
  <input type="submit">

</form>
728x90
728x90

Linux 쉘 접속

D:\docker>docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED       STATUS          PORTS                                                                 NAMES
7ce950bfb3c5   ubuntu:22.04   "/bin/bash"   4 hours ago   Up 18 minutes   0.0.0.0:1080->80/tcp, 0.0.0.0:1443->443/tcp, 0.0.0.0:1880->8080/tcp   cnssm-ubuntu
 
D:\docker>docker exec -it 7ce950bfb3c5 /bin/bash
root@0:/#

openjdk 17 설치

jdk 설치

root@0:/# apt install openjdk-17-jdk

JAVA_HOME 설정

root@0:/# echo "export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")" | tee /etc/profile.d/java_home.sh
root@0:/# source /etc/profile.d/java_home.sh

java 설치 확인

root@0:/# java --version
openjdk 17.0.13 2024-10-15
OpenJDK Runtime Environment (build 17.0.13+11-Ubuntu-2ubuntu122.04)
OpenJDK 64-Bit Server VM (build 17.0.13+11-Ubuntu-2ubuntu122.04, mixed mode, sharing)
root@0:/# javac --version
javac 17.0.13
root@0:/# echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
root@0:/#

Tomcat 설치

tomcat 계정 생성

root@0:~# useradd tomcat -s /sbin/nologin

Tomcat 다운로드 및 설치

root@0:~# wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.34/bin/apache-tomcat-10.1.34.tar.gz
root@0:~# tar xvf apache-tomcat-10.1.34.tar.gz
root@0:~# mv apache-tomcat-10.1.34 /usr/local/

tomcat 사용자 변경

root@0:~# chown tomcat:tomcat -R /usr/local/apache-tomcat-10.1.34/

tomcat 서비스 파일 생성

root@0:~# vi /etc/init.d/tomcat
#!/bin/bash

### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat at boot time
# Description:       Start Tomcat at boot time
### END INIT INFO

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export CATALINA_HOME=/usr/local/apache-tomcat-10.1.34
export JAVA_OPTS="-Xms250m -Xmx1024m"

RETVAL=$?
case $1 in
start)
    if [ -f $CATALINA_HOME/bin/startup.sh ];
    then
        echo $"Starting Tomcat"
        su -p -s /bin/sh tomcat $CATALINA_HOME/bin/startup.sh
    fi
    ;; 
stop)   
    if [ -f $CATALINA_HOME/bin/shutdown.sh ];
    then
        echo $"Stopping Tomcat"
        su -p -s /bin/sh tomcat $CATALINA_HOME/bin/shutdown.sh
    fi
    ;; 
*)
    echo $"Usage: $0 {start|stop}"
    exit 1
    ;;
esac

exit $RETVAL

서비스 등록

root@0:/# chmod +x /etc/init.d/tomcat
root@0:~# update-rc.d -f tomcat defaults
728x90
728x90

출처

컨테이너 commit 전 이미지 목록 확인

D:\docker>docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
ubuntu       22.04     0e5e4a57c249   4 months ago   117MB

컨테이너 중지

D:\docker>docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED       STATUS          PORTS                                                                 NAMES
7ce950bfb3c5   ubuntu:22.04   "/bin/bash"   4 hours ago   Up 30 minutes   0.0.0.0:1080->80/tcp, 0.0.0.0:1443->443/tcp, 0.0.0.0:1880->8080/tcp   cnssm-ubuntu
 
D:\docker>docker stop 7ce950bfb3c5
7ce950bfb3c5

컨테이너 commit

D:\docker>docker commit -p 7ce950bfb3c5 ubuntu-nginx
sha256:f41c3c19a473d68563cbffec77605a85a20b39e8cf3f1a771adbcf6be9c85a75

컨테이너 삭제

D:\docker>docker rm 7ce950bfb3c5
7ce950bfb3c5

컨테이너 commit 후 이미지 목록 확인

D:\docker>docker images
REPOSITORY     TAG       IMAGE ID       CREATED         SIZE
ubuntu-nginx   latest    f41c3c19a473   4 minutes ago   329MB
ubuntu         22.04     0e5e4a57c249   4 months ago    117MB

이미지 복사

D:\docker>docker save -o ubuntu-nginx.tar ubuntu-nginx:latest

이미지 삭제

D:\docker>docker rmi ubuntu-nginx:latest
Untagged: ubuntu-nginx:latest
Deleted: sha256:f41c3c19a473d68563cbffec77605a85a20b39e8cf3f1a771adbcf6be9c85a75
 
D:\docker>docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
ubuntu       22.04     0e5e4a57c249   4 months ago   117MB

이미지 복원

D:\docker>docker load -i ubuntu-nginx.tar
Loaded image: ubuntu-nginx:latest
 
D:\docker>docker images
REPOSITORY     TAG       IMAGE ID       CREATED          SIZE
ubuntu-nginx   latest    f41c3c19a473   12 minutes ago   329MB
ubuntu         22.04     0e5e4a57c249   4 months ago     117MB

컨터이너 생성

D:\docker>docker run -it ^
--hostname 0.0.0.0 ^
--publish 2080:80 --publish 2443:443 --publish 2880:8080 ^
--name bxmas-ubuntu ^
--restart always ^
--volume //d/docker/bxmas/bxmas_home2:/usr/local/bxmas_home ^
ubuntu-nginx:latest ^
/bin/bash

nginx 서비스 시작

root@0:/usr/local/bxmas_home# service nginx start
 * Starting Nginx Server...
728x90
728x90

Ubuntu 도커 이미지 설치

D:\docker>docker run -it ^
--hostname 0.0.0.0 ^
--publish 1080:80 --publish 1443:443 --publish 1880:8080 ^
--name bxmas-ubuntu ^
--restart always ^
--volume //d/docker/bxmas/bxmas_home:/usr/local/bxmas_home ^
ubuntu:22.04 ^
/bin/bash
 
root@0:/#

OS 업데이트

root@0:/# apt update
root@0:/# apt upgrade

Linux 쉘 접속

D:\docker>docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED       STATUS          PORTS                                                                 NAMES
7ce950bfb3c5   ubuntu:22.04   "/bin/bash"   4 hours ago   Up 18 minutes   0.0.0.0:1080->80/tcp, 0.0.0.0:1443->443/tcp, 0.0.0.0:1880->8080/tcp   cnssm-ubuntu
 
D:\docker>docker exec -it 7ce950bfb3c5 /bin/bash
root@0:/#

openjdk 17 설치

jdk 설치

root@0:/# apt install openjdk-17-jdk

JAVA_HOME 설정

root@0:/# echo "export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")" | tee /etc/profile.d/java_home.sh
root@0:/# source /etc/profile.d/java_home.sh

java 설치 확인

root@0:/# java --version
openjdk 17.0.13 2024-10-15
OpenJDK Runtime Environment (build 17.0.13+11-Ubuntu-2ubuntu122.04)
OpenJDK 64-Bit Server VM (build 17.0.13+11-Ubuntu-2ubuntu122.04, mixed mode, sharing)
root@0:/# javac --version
javac 17.0.13
root@0:/# echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64
root@0:/#

nginx 설치

nginx 계정 생성

root@0:~# useradd nginx -s /sbin/nologin

nginx 빌드 환경 설정

root@0:~# apt install gcc g++ make perl
root@0:~# mkdir nginx_source
root@0:~# cd nginx_source/
root@0:~/nginx_source# apt install wget
root@0:~/nginx_source# wget https://nginx.org/download/nginx-1.20.1.tar.gz
root@0:~/nginx_source# tar xvf nginx-1.20.1.tar.gz
root@0:~/nginx_source# wget  https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz
root@0:~/nginx_source# tar xvf pcre-8.45.tar.gz
root@0:~/nginx_source# wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
root@0:~/nginx_source# tar -xzvf openssl-1.1.1l.tar.gz
root@0:~/nginx_source# wget https://www.zlib.net/fossils/zlib-1.2.11.tar.gz
root@0:~/nginx_source# tar xvf zlib-1.2.11.tar.gz
root@0:~/nginx_source# cd nginx-1.20.1/
root@0:~/nginx_source/nginx-1.20.1#

configure

root@0:~/nginx_source/nginx-1.20.1# ./configure \
--user=nginx \
--group=nginx \
--with-http_sub_module \
--with-zlib=../zlib-1.2.11 \
--with-pcre=../pcre-8.45 \
--with-openssl=../openssl-1.1.1l \
--with-http_ssl_module \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/bxmas_home/nginx_conf/nginx.conf
 
Configuration summary
  + using PCRE library: ../pcre-8.45
  + using OpenSSL library: ../openssl-1.1.1l
  + using zlib library: ../zlib-1.2.11
 
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/bxmas_home/nginx_conf"
  nginx configuration file: "/usr/local/bxmas_home/nginx_conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

make

root@0:~/nginx_source/nginx-1.20.1# make
 
-lcrypt ../pcre-8.45/.libs/libpcre.a ../openssl-1.1.1l/.openssl/lib/libssl.a ../openssl-1.1.1l/.openssl/lib/libcrypto.a ../zlib-1.2.11/libz.a \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/bxmas_home/nginx_conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/root/nginx_source/nginx-1.20.1'

make install

root@0:~/nginx_source/nginx-1.20.1# make install
make -f objs/Makefile install
make[1]: Entering directory '/root/nginx_source/nginx-1.20.1'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
        || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
        || mv '/usr/local/nginx/sbin/nginx' \
                '/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/bxmas_home/nginx_conf' \
        || mkdir -p '/usr/local/bxmas_home/nginx_conf'
cp conf/koi-win '/usr/local/bxmas_home/nginx_conf'
cp conf/koi-utf '/usr/local/bxmas_home/nginx_conf'
cp conf/win-utf '/usr/local/bxmas_home/nginx_conf'
test -f '/usr/local/bxmas_home/nginx_conf/mime.types' \
        || cp conf/mime.types '/usr/local/bxmas_home/nginx_conf'
cp conf/mime.types '/usr/local/bxmas_home/nginx_conf/mime.types.default'
test -f '/usr/local/bxmas_home/nginx_conf/fastcgi_params' \
        || cp conf/fastcgi_params '/usr/local/bxmas_home/nginx_conf'
cp conf/fastcgi_params \
        '/usr/local/bxmas_home/nginx_conf/fastcgi_params.default'
test -f '/usr/local/bxmas_home/nginx_conf/fastcgi.conf' \
        || cp conf/fastcgi.conf '/usr/local/bxmas_home/nginx_conf'
cp conf/fastcgi.conf '/usr/local/bxmas_home/nginx_conf/fastcgi.conf.default'
test -f '/usr/local/bxmas_home/nginx_conf/uwsgi_params' \
        || cp conf/uwsgi_params '/usr/local/bxmas_home/nginx_conf'
cp conf/uwsgi_params \
        '/usr/local/bxmas_home/nginx_conf/uwsgi_params.default'
test -f '/usr/local/bxmas_home/nginx_conf/scgi_params' \
        || cp conf/scgi_params '/usr/local/bxmas_home/nginx_conf'
cp conf/scgi_params \
        '/usr/local/bxmas_home/nginx_conf/scgi_params.default'
test -f '/usr/local/bxmas_home/nginx_conf/nginx.conf' \
        || cp conf/nginx.conf '/usr/local/bxmas_home/nginx_conf/nginx.conf'
cp conf/nginx.conf '/usr/local/bxmas_home/nginx_conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
        || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
        || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory '/root/nginx_source/nginx-1.20.1'

서비스 등록

/etc/init.d/nginx에서 환경파일(nginx.conf) 경로 수정 필요

root@0:~# wget --no-check-certificate https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
root@0:~# chmod +x /etc/init.d/nginx
root@0:~# update-rc.d -f nginx defaults
728x90
728x90

출처

Rocky Linux 이미지 다운로드

D:\docker>docker pull rockylinux:9
9: Pulling from library/rockylinux
446f83f14b23: Pull complete
Digest: sha256:d7be1c094cc5845ee815d4632fe377514ee6ebcf8efaed6892889657e5ddaaa6
Status: Downloaded newer image for rockylinux:9
docker.io/library/rockylinux:9
 
What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview rockylinux:9

Rocky Linux 컨테이너 실행

D:\docker>docker run -it --name rockylinux9_container rockylinux:9 /bin/bash

Docker 컨테이너 목록 확인

D:\docker>docker ps -al
CONTAINER ID   IMAGE          COMMAND       CREATED             STATUS         PORTS     NAMES
0742e89fc2d8   rockylinux:9   "/bin/bash"   About an hour ago   Up 5 seconds             rockylinux9_container

Docker 컨테이너 종료

D:\docker>docker stop rockylinux9_container
rockylinux9_container

Docker 종료된 컨테이너 목록 확인

D:\docker>docker ps -al
CONTAINER ID   IMAGE          COMMAND       CREATED             STATUS                       PORTS     NAMES
0742e89fc2d8   rockylinux:9   "/bin/bash"   About an hour ago   Exited (137) 6 seconds ago             rockylinux9_container

Docker 컨테이너 삭제

D:\docker>docker rm rockylinux9_container
rockylinux9_container

Docker 이미지 목록 확인

D:\docker>docker images
REPOSITORY                 TAG       IMAGE ID       CREATED         SIZE
rockylinux                 9         9cc24f05f309   13 months ago   176MB

Docker 이미지 삭제

D:\docker>docker rmi 9cc24f05f309
Untagged: rockylinux:9
Untagged: rockylinux@sha256:d7be1c094cc5845ee815d4632fe377514ee6ebcf8efaed6892889657e5ddaaa6
Deleted: sha256:9cc24f05f309508aa852967ab1e3b582b302afc92605c24ce27715c683acd805
Deleted: sha256:44343de3ea1d3f71f143967c71a91df76138a17a21ac56642f3c0f2a64b07dce

Rocky Linux 컨테이너 실행

D:\docker>docker run -it ^
--hostname 0.0.0.0 ^
--publish 10022:22 --publish 10080:80 --publish 10443:443 --publish 18080:8080 --publish 18443:8443 ^
--name rockylinux ^
--restart always ^
--volume //d/docker/rockylinux/bluexmas_home:/usr/local/bluexmas_home ^
rockylinux/rockylinux:9.5 ^
/bin/bash
 
Unable to find image 'rockylinux/rockylinux:9.5' locally
9.5: Pulling from rockylinux/rockylinux
3442e16c7069: Pull complete
Digest: sha256:149fd31d916038eb1084d0e051537e279d7afcd5de0b365254e8fa3c3ef12bad
Status: Downloaded newer image for rockylinux/rockylinux:9.5
[root@0 /]#

Rocky Linux /bin/bash 접속

[root@0 /]# exit
exit

D:\docker>docker ps -l
CONTAINER ID   IMAGE                       COMMAND       CREATED          STATUS         PORTS
                                                                                          NAMES
554f3e3a7bd4   rockylinux/rockylinux:9.5   "/bin/bash"   37 seconds ago   Up 6 seconds   0.0.0.0:10022->22/tcp, 0.0.0.0:10080->80/tcp, 0.0.0.0:10443->443/tcp, 0.0.0.0:18080->8080/tcp, 0.0.0.0:18443->8443/tcp   rockylinux

D:\docker>docker exec -it 554f3e3a7bd4 /bin/bash
[root@0 /]#

 

728x90
728x90

출처

도커 이미지 받기

D:\docker> docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce

Digest: sha256:bef394818ac85471965400e6a86b5c5de3994ba6400f32b20b16eec266c5f3b3
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview gitlab/gitlab-ce

도커 이미지 목록 조회

D:\docker\gitlab-ce>docker image ls
REPOSITORY                 TAG       IMAGE ID       CREATED        SIZE
gitlab/gitlab-ce           latest    2eac78f2ca26   36 hours ago   3.02GB

컨테이너 생성

D:\docker\gitlab-ce>docker run --detach ^
--hostname 192.168.0.30 ^
--publish 1980:80 --publish 1922:22 --publish 19443:443 ^
--name gitlab-ce ^
--restart always ^
--volume //d/docker/gitlab-ce/config:/etc/gitlab ^
--volume //d/docker/gitlab-ce/logs:/var/log/gitlab ^
--volume //d/docker/gitlab-ce/data:/var/opt/gitlab ^
gitlab/gitlab-ce:latest
d83e65ca9a26822433babb2d08b45eb04b9dbb73413a6c7d7f207dc09f51307b

브라우져 접속 (http://localhost:1980/)

Gitlab root 계정 암호 확인

docker 접속

D:\docker\gitlab-ce>docker exec -it gitlab-ce /bin/bash
root@192:/#

root 계정 암호 확인 (사이트에 접속 해서 암호는 수정할 것 - 까먹지 말자 : Test1234~~)

root@192:/# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: UvNmajhoONurwfCUJjAT2ShZCY741dzIJJsbuyjO6Fs=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

실행 포트 확인

D:\docker>netstat -nao | findstr 8096
  TCP    0.0.0.0:8096           0.0.0.0:0              LISTENING       12976
  TCP    192.168.0.30:7634      192.168.0.30:8096      ESTABLISHED     19636
  TCP    192.168.0.30:8096      192.168.0.30:7631      TIME_WAIT       0
  TCP    192.168.0.30:8096      192.168.0.30:7634      ESTABLISHED     12976
  TCP    192.168.0.30:8096      192.168.0.30:7635      TIME_WAIT       0
  TCP    192.168.0.30:8096      192.168.0.30:7638      TIME_WAIT       0
  TCP    192.168.0.30:8096      192.168.0.30:7641      TIME_WAIT       0
  TCP    [::]:8096              [::]:0                 LISTENING       12976
  TCP    [::1]:7468             [::1]:8096             ESTABLISHED     19636
  TCP    [::1]:7506             [::1]:8096             ESTABLISHED     19636
  TCP    [::1]:8096             [::]:0                 LISTENING       17952
  TCP    [::1]:8096             [::1]:7468             ESTABLISHED     17952
  TCP    [::1]:8096             [::1]:7506             ESTABLISHED     17952
  TCP    [::1]:8096             [::1]:7603             TIME_WAIT       0
  TCP    [::1]:8096             [::1]:7604             TIME_WAIT       0
  TCP    [::1]:8096             [::1]:7605             TIME_WAIT       0
  TCP    [::1]:8096             [::1]:7606             TIME_WAIT       0
  TCP    [::1]:8096             [::1]:7795             TIME_WAIT       0
  TCP    [::1]:8096             [::1]:7796             TIME_WAIT       0

실행중인 컨테이너 목록 조회

D:\docker\gitlab-ce>docker ps
CONTAINER ID   IMAGE                     COMMAND             CREATED         STATUS                   PORTS     NAMES
15a159a46350   gitlab/gitlab-ce:latest   "/assets/wrapper"   7 minutes ago   Up 7 minutes (healthy)             gitlab-ce

컨테이너 실행 중지

D:\docker\gitlab-ce>docker stop 15a159a46350
15a159a46350

컨테이너 삭제

D:\docker\gitlab-ce>docker rm 15a159a46350
15a159a46350

로그 확인

D:\docker\gitlab-ce>docker logs -f gitlab-ce
728x90
728x90

구출처

OpenCV 패키지 설치

(venv) D:\workspace.python\cubotino>pip install opencv_python opencv_contrib_python_headless opencv_contrib_python opencv_python_headless numpy==1.26.4

main.py

import cv2

def detect_faces(image_path):
    # 이미지 파일을 로드합니다.
    image = cv2.imread(image_path)

    # 이미지를 회색으로 변환합니다. (얼굴 인식은 흑백 이미지에서 수행되므로)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # 얼굴 인식을 위해 얼굴 검출기를 로드합니다.
    print(f'cv data path = {cv2.data.haarcascades}')
    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

    # 이미지에서 얼굴을 검출합니다.
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

    # 검출된 얼굴 주위에 사각형을 그립니다.
    for (x, y, w, h) in faces:
        cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

    # 결과 이미지를 화면에 출력합니다.
    cv2.imshow('Face Detection', image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

# 얼굴을 인식할 이미지를 지정합니다.
image_path = 'face.jpg'

# 얼굴 인식 함수를 호출합니다.
detect_faces(image_path)

실행

D:\workspace.python\cubotino\venv\Scripts\python.exe D:\workspace.python\cubotino\main.py 
cv data path = D:\workspace.python\cubotino\venv\Lib\site-packages\cv2\data\

728x90

+ Recent posts