function [negSample, p] = SelectNeg(I, param, opt)
tmplsize = opt.tmplsize;
numNeg = opt.negNum;
r = opt.r;

param_p = param; 
param = affparam2geom(param);
x = param(1);
y = param(2);
width = param(3)*tmplsize(2); 

height = width*param(5);

[nrows, ncols] = size(I);
negSample = zeros(tmplsize(1),tmplsize(2), numNeg);
p = zeros(6,numNeg);

inner = sqrt(width^2+height^2)/2+sqrt(tmplsize(1)^2+tmplsize(2)^2)/2; %´óÄÚ»·
out = r*inner;
count=0;
while (1)
    p_amplitude = inner+(out-inner)*rand(1);
    p_angle = 2*pi*rand(1);
    xx = p_amplitude*cos(p_angle);
    xx = round(xx)+x; 
    yy = p_amplitude*sin(p_angle);
    yy = round(yy)+y;
        
    left = round(xx - width/2);
    right = round(xx + width/2);
    top = round(yy - height/2);
    bottom = round(yy + height/2);
    if left>0 && right<ncols && top>0 && bottom<nrows
        count = count+1;
        param_n = param_p;
        param_n(1:2) = [xx yy];
        negSample(:,:,count) = warpimg(I, param_n, tmplsize);
        
        p(:,count) = param_n; 
    end
    if count == numNeg
        break;
    end
end
