关于MATLAB中多目标的跟踪。

用matlab实现,动态的多目标追踪,很急!!!!!!!... 用matlab实现,动态的多目标追踪,很急!!!!!!! 展开
 我来答
宝宝表白
2011-06-14 · 超过22用户采纳过TA的回答
知道答主
回答量:79
采纳率:0%
帮助的人:0
展开全部
下面是camshift物体追踪代码,需要你用avi视频测试,matlab对avi视频格式要求比较严格。但是可以试试mmreader函数读取视频。
% Adam Kukucka
% Zach Clay
% Marcelo Molina
% CSE 486 Project 3
function [ trackmov probmov centers ] = camshift
% ******************************************************************
% initialize vari ables
% ******************************************************************
rmin = 0; %min row value for search window
rmax = 0; %max row value for search window
cmin = 0; %min col value for search window
cmax = 0; %max col value for search window
numofframes = 0; %number of frames in the avi
threshold = 1; %threshold for convergence
centerold = [0 0]; %for convergence... previous center of window
centernew = [0 0]; %for convergence... new center of window
% ******************************************************************
% Pre code... load movie and select initial frame
% ******************************************************************
% prompt user for avi file name
%%%%%user_entry = input('Please enter an avi filename: ','s');
% load the avi file... handle is M
%%%%M = aviread(user_entry);
M=aviread('8888.avi');
% get number of frames
[dontneed numberofframes] = size(M)
% initialize matrix to hold center coordinates
imagecenters = zeros(numberofframes, 2);
% extract the first frame from the avi
Frame1 = M(1,1);
Image1 = frame2im(Frame1);
%%% ********** images(:, :, numberofframes) = G(:,:);
% get search window for first frame
[ cmin, cmax, rmin, rmax ] = select( Image1 );
cmin = round(cmin);
cmax = round(cmax);
rmin = round(rmin);
rmax = round(rmax);
wsize(1) = abs(rmax - rmin);
wsize(2) = abs(cmax - cmin);
% create histogram
% translate to hsv
hsvimage = rgb2hsv(Image1);
% pull out the h
huenorm = hsvimage(:,:,1);
% scale to 0 to 255
hue = huenorm*255;
% set unit type
hue=uint8(hue);
% Getting Histogram of Image:
histogram = zeros(256);
for i=rmin:rmax
for j=cmin:cmax
index = uint8(hue(i,j)+1);
%count number of each pixel
histogram(index) = histogram(index) + 1;
end
end
% ******************************************************************
% Algorithm from pdf
% ******************************************************************
aviobj1 = avifile('example3.avi');
aviobj2 = avifile('example4.avi');
% for each frame
for i = 1:200
disp('Processing frame');
disp(i);
Frame = M(1, i);
I = frame2im(Frame);

% translate to hsv
hsvimage = rgb2hsv(I);
% pull out the h
huenorm = hsvimage(:,:,1);
% scale to 0 to 255
hue = huenorm*255;
% set unit type
hue=uint8(hue);
[rows cols] = size(hue);

% choose initial search window
% the search window is (cmin, rmin) to (cmax, rmax)

% create a probability map
probmap = zeros(rows, cols);
for r=1:rows
for c=1:cols
if(hue(r,c) ~= 0)
probmap(r,c)= histogram(hue(r,c));
end
end
end
probmap = probmap/max(max(probmap));
probmap = probmap*255;

count = 0;

rowcenter = 0; % any number just so it runs through at least twice
colcenter = 0;
rowcenterold = 30;
colcenterold = 30;
% Mean Shift for 15 iterations or until convergence(the center doesnt
% change)
while (((abs(rowcenter - rowcenterold) > 2) && (abs(colcenter - colcenterold) > 2)) || (count < 15) )
%for j = 1:5
%disp('meanshift');
% disp(j);
rmin = rmin - 7; %increase window size and check for center
rmax = rmax + 7;
cmin = cmin - 7;
cmax = cmax + 7;

rowcenterold = rowcenter; %save old center for convergence check
colcenterold = colcenter;

[ rowcenter colcenter M00 ] = meanshift(I, rmin, rmax, cmin,...
cmax, probmap);
% given image (I), search window(rmin rmax cmin cmax)
% returns new center (colcenter, rowcenter) for window and
% zeroth moment (Moo)

% redetermine window around new center
rmin = round(rowcenter - wsize(1)/2);
rmax = round(rowcenter + wsize(1)/2);
cmin = round(colcenter - wsize(2)/2);
cmax = round(colcenter + wsize(2)/2);
wsize(1) = abs(rmax - rmin);
wsize(2) = abs(cmax - cmin);

count = count + 1;
end

% mark center on image

%save image
G = .2989*I(:,:,1)...
+.5870*I(:,:,2)...
+.1140*I(:,:,3);
trackim=G;

%make box of current search window on saved image
for r= rmin:rmax
trackim(r, cmin) = 255;
trackim(r, cmax) = 255;
end
for c= cmin:cmax
trackim(rmin, c) = 255;
trackim(rmax, c) = 255;
end
aviobj1 = addframe(aviobj1,trackim);
aviobj2 = addframe(aviobj2,probmap);

%create image movie, and probability map movie
trackmov(:,:,i)= trackim(:,:);
probmov(:,:,i) = probmap(:,:);

% save center coordinates as an x, y by doing col, row
centers(i,:) = [colcenter rowcenter];
% Set window size = 2 * (Moo/256)^1/2
windowsize = 2 * (M00/256)^.5;

% get side length ... window size is an area so sqrt(Area)=sidelength
sidelength = sqrt(windowsize);

% determine rmin, rmax, cmin, cmax
rmin = round(rowcenter-sidelength/2);
rmax = round(rowcenter+sidelength/2);
cmin = round(colcenter-sidelength/2);
cmax = round(colcenter+sidelength/2);
wsize(1) = abs(rmax - rmin);
wsize(2) = abs(cmax - cmin);
end
% end for loop
% Adam Kukucka
% Zach Clay
% Marcelo Molina
% CSE 486 Project 3
function [ rowcenter colcenter M00 ] = meanshift(I, rmin, rmax, cmin,...
cmax, probmap)
%inputs
% rmin, rmax, cmin, cmax are the coordiantes of the window
% I is the image
%outputs
% colcenter rowcenter are the new center coordinates
% Moo is the zeroth mean
% **********************************************************************
% initialize
% **********************************************************************
M00 = 0; %zeroth mean
M10 = 0; %first moment for x
M01 = 0; %first moment for y
histdim = (0:1:255); % dimensions of histogram... 0 to 255, increment by 1
[rows cols] = size(I);
cols = cols/3; % **********************8
% **********************************************************************
% Main code
% **********************************************************************

% determine zeroth moment
for c = cmin:cmax
for r = rmin:rmax
M00 = M00 + probmap(r, c);
end
end
% determine first moment for x(col) and y(row)
for c = cmin:cmax
for r = rmin:rmax
M10 = M10 + c*probmap(r,c);
M01 = M01 + r*probmap(r,c);
end
end
% determine new centroid
% x is cols
colcenter = M10/M00;
% y is rows
rowcenter = M01/M00;

% Adam Kukucka
% Zach Clay
% Marcelo Molina
% CSE 486 Project 3
function [ cmin, cmax, rmin, rmax ] = select( I )
%UNTITLED1 Summary of this function goes here
% Detailed explanation goes here

% for array... x is cols, y is rows
image(I);
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint'); %mouse pressed
rectregion = rbbox;
point2 = get(gca,'CurrentPoint');
point1 = point1(1,1:2); % extract col/row min and maxs
point2 = point2(1,1:2);
lowerleft = min(point1, point2);
upperright = max(point1, point2);
cmin = round(lowerleft(1));
cmax = round(upperright(1));
rmin = round(lowerleft(2));
rmax = round(upperright(2));
更多追问追答
追问
。。。这个代码我下载了,但是有错。。。。。。
追答
我也是遇到了小问题。在读取视频的时候老是没办法解码原avi视频,顺便问一句,大侠知道matlab的avi视频格式设置怎么弄么?
Sievers分析仪
2024-10-13 广告
是的。传统上,对于符合要求的内毒素检测,最终用户必须从标准内毒素库存瓶中构建至少一式两份三点标准曲线;必须有重复的阴性控制;每个样品和PPC必须一式两份。有了Sievers Eclipse内毒素检测仪,这些步骤可以通过使用预嵌入的内毒素标准... 点击进入详情页
本回答由Sievers分析仪提供
2lqj4vpvj
2011-06-15 · TA获得超过1533个赞
知道大有可为答主
回答量:1653
采纳率:0%
帮助的人:556万
展开全部

将下属两个目标函数分别保存在两个m文件中
function f1=func1(x) %第一目标函数
f1=x(:,1).*x(:,1)./4+x(:,2).*x(:,2)./4;
function f2=func2(x) %第二目标函数
f2=x(:,1).*(1-x(:,2))+10;

function GA()
clear;clc;close all
NIND=100; %个体数目
MAXGEN=50; %最大遗传代数
NVAR=2; %变量个数
PRECI=20; %变量的二进制位数
GGAP=0.9; %代沟
trace1=[];trace2=[];trace3=[]; %性能跟踪
%建立区域描述器
% rep([PRECI],[1,NVAR])
FieldD=[rep([PRECI],[1,NVAR]);rep([1;2],[1,NVAR]);rep([1;0;1;1],[1,NVAR])];
Chrom=crtbp(NIND,NVAR*PRECI); %初始种群
v=bs2rv(Chrom,FieldD) ; %初始种群十进制转换
gen=1;
while gen<MAXGEN,
[NIND,N]=size(Chrom);
M=fix(NIND/2);
ObjV1=func1(v(1:M,:)); %分组后第一目标函数值
FitnV1=ranking(ObjV1); %分配适应度值
SelCh1=select('sus',Chrom(1:M,:),FitnV1,GGAP); %选择
ObjV2=func2(v(M+1:NIND,:)); %分组后第二目标函数值
FitnV2=ranking(ObjV2); %分配适应度值
SelCh2=select('sus',Chrom(M+1:NIND,:),FitnV2,GGAP); %选择
SelCh=[SelCh1;SelCh2]; %合并
SelCh=recombin('xovsp',SelCh,0.7); %重组
Chrom=mut(SelCh); %变异
v=bs2rv(Chrom,FieldD);
trace1(gen,1)=min(func1(v));
trace1(gen,2)=sum(func1(v))/length(func1(v));
trace2(gen,1)=min(func2(v));
trace2(gen,2)=sum(func2(v))/length(func2(v));
trace3(gen,1)=min(func1(v)+func2(v));
trace3(gen,2)=sum(func1(v))/length(func1(v))+sum(func2(v))/length(func2(v));
gen=gen+1;
end
figure(1);clf;
plot(trace1(:,1));hold on;plot(trace1(:,2),'-.');
plot(trace1(:,1),'.');plot(trace1(:,2),'.');grid on;
legend('解的变化','种群均值的变化')
xlabel('迭代次数');ylabel('目标函数值');
figure(2);clf;
plot(trace2(:,1));hold on;
plot(trace2(:,2),'-.');
plot(trace2(:,1),'.');
plot(trace2(:,2),'.');grid;
legend('解的变化','种群均值的变化');
xlabel('迭代次数');ylabel('目标函数值');
figure(3);clf;
plot(trace3(:,1));hold on;
plot(trace3(:,2),'-.');
plot(trace3(:,1),'.');
plot(trace3(:,2),'.');grid;
legend('解的变化','种群均值的变化');
xlabel('迭代次数');ylabel('目标函数值');
figure(4);clf;plot(func1(v));hold on;
plot(func2(v),'r-.');grid;
追问
请问这个怎么实现动态视频里面的多目标跟踪呢?运行出来的都是曲线图片啊,而且也没有加载视频的语句。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
推荐于2016-08-20
展开全部
#include <stdio.h>
#include <string.h>
int ac(int ab[],int k,int len);
main()
{
int a[6]={2,52,12,21,52,65};
int len,k=2,i;
len=strlen(a);
ac(a[],k,len);
for(i=0;i<len;i++)
printf("%d\t",a[i]);
}
int ac(int a[],int k,int len)
{ int i,j,t,temp,count;
count=0;
k=k%len;
if(k)
{
i=0;
while(count<len){
j=i;t=i;
temp=a[i];
while((j=(j-k+len)%len)!=i)
{ a[t]=a[j];
t=j;
count++;
}
a[t]=temp; count++;
i++;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式