CV
Computer Vision
Computer vision. The AI field of understanding images and video. Object detection, segmentation, OCR.
Computer Vision
Computer vision. The AI field of understanding images and video. Object detection, segmentation, OCR.
Computer Vision (CV) is a core field of AI that enables machines to extract and understand meaningful information from images and videos. It mimics the human visual system to automate a variety of visual tasks such as object recognition, scene understanding, and 3D reconstruction.
The history of CV dates back to early research at MIT in the 1960s, but after AlexNet showed overwhelming performance at the ImageNet competition in 2012, deep learning-based CV became mainstream. Since then, it has developed rapidly with the emergence of classification models such as ResNet and EfficientNet and object detection models such as YOLO and Faster R-CNN.
The main tasks of CV include Image Classification, Object Detection, Semantic Segmentation, Instance Segmentation, Pose Estimation, and OCR (Optical Character Recognition). Each task requires different architectures and training methods.
In practice, CV is widely applied to road recognition in autonomous vehicles, disease detection in medical imaging, quality inspection in manufacturing, facial recognition in security systems, and unmanned checkout systems in retail. Recently, Vision Transformer and multimodal models (CLIP, GPT-4V) are opening up new possibilities.
# OpenCV와 PyTorch를 활용한 객체 탐지
import cv2
import torch
from torchvision import transforms
from torchvision.models.detection import fasterrcnn_resnet50_fpn_v2, FasterRCNN_ResNet50_FPN_V2_Weights
# 사전 학습된 Faster R-CNN 모델 로드
weights = FasterRCNN_ResNet50_FPN_V2_Weights.DEFAULT
model = fasterrcnn_resnet50_fpn_v2(weights=weights)
model.eval()
# 이미지 전처리
preprocess = weights.transforms()
# 이미지 로드 및 추론
image = cv2.imread("sample.jpg")
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_tensor = preprocess(torch.from_numpy(image_rgb).permute(2, 0, 1))
# 객체 탐지 수행
with torch.no_grad():
predictions = model([image_tensor])[0]
# 결과 시각화 (confidence > 0.7인 객체만)
categories = weights.meta["categories"]
for box, label, score in zip(predictions['boxes'], predictions['labels'], predictions['scores']):
if score > 0.7:
x1, y1, x2, y2 = box.int().tolist()
class_name = categories[label]
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(image, f"{class_name}: {score:.2f}",
(x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imwrite("detected.jpg", image)
print(f"탐지된 객체 수: {len([s for s in predictions['scores'] if s > 0.7])}")
"If we apply YOLOv8 to the defect detection system, real-time processing is possible. The current line requires processing 30 frames per second, and on a V100 GPU, YOLOv8-m reaches about 45fps."
"In object detection, IoU (Intersection over Union) is the value obtained by dividing the overlapping area of the predicted bounding box and the ground-truth box by their total combined area. Typically, an IoU of 0.5 or higher is considered a True Positive, and mAP is calculated based on this."
"In image preprocessing, the order of resize followed by normalize matters. Pretrained models are normalized with ImageNet statistics (mean=[0.485, 0.456, 0.406]), so you need to match them in the same way."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
If a model trained on ImageNet is applied directly to medical imaging or satellite photos, its performance drops significantly. Fine-tuning on data from the relevant domain is essential.
Processing high-resolution images as they are causes memory shortages and slower speeds. Apply appropriate resizing or sliding window techniques depending on the task.
Use Accuracy for classification, mAP for detection, and IoU/Dice for segmentation. You must choose the right evaluation metric for the task to measure model performance accurately.