【水果識別】基于計算機視覺實現橙子數量識別含Matlab源碼
【水果識別】基于計算機視覺實現橙子數量識別含Matlab源碼
TT_Matlab
博主簡介:擅長智能優化算法、神經網絡預測、信號處理、元胞自動機、圖像處理、路徑規劃、無人機等多種領域的Matlab仿真,完整matlab代碼或者程序定制加qq1575304183。
1 簡介
在現實生活中成人識別水果是十分簡易的但對于幼兒來說在沒有實物之前是無法識別水果的,因此本文設計了一個簡易水果識別系統為幼兒在電子設備上識別水果提供可能.本文通過matlab GUI設計了一個水果識別系統界面并通過對水果圖像進行二值化處理,邊緣處理最后實現了橙子數量識別.
2 部分代碼
function [t,em] = otsuthresh(counts) %#codegen
%
OTSUTHRESH Global histogram threshold using Otsu
’s method - M-to-C codegen.
%
Copyright 2015 The MathWorks, Inc.
%
Syntax
%
------
%
%
[t,em] = otsuthresh(counts)
%
%
Input Specs
%
-----------
%
%
counts:
%
numeric
%
vector
%
real
%
finite
%
non-sparse
%
non-negative
%
%
Output Specs
%
------------
%
%
t:
%
scalar
%
double
%
in [0,1]
%
%
em:
%
scalar
%
double
%
in [0,1]
%
%
Validate counts
validateattributes(counts,{’numeric’}, ...
{’vector’,’real’,’finite’,’nonsparse’,’nonnegative’},mfilename,’COUNTS’);
%
Number of bins
num_bins = numel(counts);
%
Number of elements
num_elems = 0;
for k = 1:num_bins
num_elems = num_elems + double(counts(k));
end
%
CDF of the histogram
omega = coder.nullcopy(zeros(num_bins,1));
omega(1) = double(counts(1))/num_elems;
mu = coder.nullcopy(zeros(num_bins,1));
mu(1) = omega(1);
for k = 2:num_bins
% PDF
p = double(counts(k))/num_elems;
% CDF
omega(k) = omega(k-1) + p;
% "weighted" CDF
mu(k) = mu(k-1) + p*k;
end
mu_t = mu(end);
%
Equation 18 in the paper
sigma_b_squared = coder.nullcopy(zeros(num_bins,1));
maxval = -coder.internal.inf;
for k = 1:num_bins
sigma_b_squared(k) = (mu_t*omega(k) - mu(k))^2 / (omega(k)*(1-omega(k)));
maxval = max(maxval,sigma_b_squared(k));
end
%
Find the location of the maximum value of sigma_b_squared.
%
If maxval is NaN, meaning that sigma_b_squared
%
is all NaN, then return 0.
isfinite_maxval = isfinite(maxval);
if isfinite_maxval
% The maximum may extend over several bins,
% so average together the locations.
idx = double(0);
num_maxval = double(0);
for k = 1:num_bins
idx = idx + k * double(sigma_b_squared(k) == maxval);
num_maxval = num_maxval + 1 * double(sigma_b_squared(k) == maxval);
end
idx = idx / num_maxval;
% Normalize the threshold to the range [0,1]
t = (idx - 1) / (num_bins - 1);
else
t = 0;
end
%
Compute the effectiveness metric
if nargout > 1
if isfinite_maxval
d = 0;
for k = 1:num_bins
d = d + double(counts(k))/num_elems * k^2;
end
em = maxval/(d - mu_t^2);
else
em = 0;
end
end
3 仿真結果
4 參考文獻
[1]陽江平. 基于計算機視覺的果蔬識別方法研究[D]. 大連理工大學.
博主簡介:擅長智能優化算法、神經網絡預測、信號處理、元胞自動機、圖像處理、路徑規劃、無人機等多種領域的Matlab仿真,相關matlab代碼問題可私信交流。
部分理論引用網絡文獻,若有侵權聯系博主刪除。