#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time :2022/2/17 14:53
# @Author :weiz
import glob
import os
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import cv2
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
import numpy as np
def get_resize():
width = int(1920 * 0.5)
height = int(1080 * 0.5)
return (width, height)
def format_set(good_file_path, ng_file_path):
"""
格式化数据,使之可以被svm训练
:param good_file_path:
:param ng_file_path:
:return:
"""
x = [] # 图片数据:w*h, n
y = [] # 标签: ng:0 good:1,
image_path_list = glob.glob(os.path.join(good_file_path, "*.png"))
for imgae_path in image_path_list:
img = cv2.imread(imgae_path, 0)
img = cv2.resize(img, get_resize(), interpolation=
svm测试性代码
最新推荐文章于 2024-09-26 11:01:02 发布