【CI框架】关于result_array与row_array

区别如下
row_array返回的为一维数组
result_array返回的为二维数组

/*
	 *根据起始日期和类型得到总数量和总金额
	 */
	public function group_by_date_type($sdate,$edate,$ype){
		$this->db->select("IFNULL(sum(num),'0') as total,IFNULL(count(num),'0') as num");
		$this->db->from('t_b');
		if($sdate != 0){
			$this->db->where("DATE_FORMAT(date,'%Y-%m-%d')>=",$sdate);
		}
		if($edate != 0){
			$this->db->where("DATE_FORMAT(date,'%Y-%m-%d')<=",$edate);
		}
		if(!empty($type)){
			$this->db->where_in('t_b.type',$ype);
		}
		$this->db->where('b_del=0');
		$query = $this->db->get();
		return $query->row_array();//标记值1
	}

路上标记值 若返回时的数组 且为$sum[]
要使用到$sum['total']$sum['num']
使用row_array()则可以直接使用
使用result_array() 则需要改为$sum[0]['total']``$sum[0]['num']

import cv2 import numpy as np import os # 提取图像的HOG特征 def get_hog_features(image): hog = cv2.HOGDescriptor() hog_features = hog.compute(image) return hog_features # 加载训练数据集 train_data = [r"I:\18Breakageratecalculation\SVM run\detection_cut\whole\train128"] train_labels = [r"I:\18Breakageratecalculation\SVM run\detection_cut\whole\train128\labels.txt"] num_samples = 681 for i in range(num_samples): img = cv2.imread(str(i).zfill(3)+'.jpg') hog_features = get_hog_features(image) hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) color_hist = cv2.calcHist([hsv_image], [0, 1], None, [180, 256], [0, 180, 0, 256]) color_features = cv2.normalize(color_hist, color_hist).flatten() train_data.append(hog_features) train_labels.append(labels[i]) # 训练SVM模型 svm = cv2.ml.SVM_create() svm.setType(cv2.ml.SVM_C_SVC) svm.setKernel(cv2.ml.SVM_LINEAR) svm.train(np.array(train_data), cv2.ml.ROW_SAMPLE, np.array(train_labels)) # 对测试图像进行分类 test_image = cv2.imread('I:\18Breakageratecalculation\mask-slic use\maskSLIC-master\result\split\result2\maskslic2_roi.png', 0) test_features = get_hog_features(test_image) result = svm.predict(test_features.reshape(1,-1)) # 显示分割结果 result_image = np.zeros(test_image.shape, np.uint8) for i in range(test_image.shape[0]): for j in range(test_image.shape[1]): if result[i,j] == 1: result_image[i,j] = 255 cv2.imshow('I:\18Breakageratecalculation\mask-slic use\maskSLIC-master\result\split\result2\Result.png', result_image) cv2.waitKey(0) cv2.destroyAllWindows()
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值