人物在图像中的位置
location of person in the Image
如何把房间分成很多区域,然后在哪个区域找到一个人的位置。
我在 matlab 中使用背景减法来检测房间里的人,所以我可以扩展这项工作以找出人在图像中的位置,如果我将图像分成多个区域,甚至可以在区域中找出人的位置??
感谢您的帮助
问候
将图像分成几个小节
我在这里提供的方法只是 another Whosebug answer.
的略微修改版本
If you want to divide a matrix into submatrices, one way is to use the mat2cell
function to break the matrix up and store each sub-matrix in a cell of a cell array.
以这个例子为例,一个60x50的矩阵在一个单元格中被分成6个矩阵(如下图所示):
C = mat2cell(I, [10 20 30], [25 25]);
更一般地说,要将您的图像分割成大小相同的 "zones",以下方法可行:
im_rows = 256; % Replace this with the number of rows in your image
im_cols = 256; % Replace this with the number of columns in your image
C = mat2cell(I, [im_rows/2 im_rows/2], [im_cols/2 im_cols/2])
Zone1 = C{1,1};
Zone2 = C{1,2};
Zone3 = C{2,1};
% ... and so on
C
现在是一个 2×2 元胞数组 - 4 "zones" - 每个存储原始图像的四分之一,I
.
检测图像中的人物
现在您已将图像 I
分成几个区域,您可以开始检测每个特定区域内的人。
如果您可以访问 MATLAB 的 vision
包,那么您可以利用 PeopleDetector
object。根据文档,vision
软件包使检测人员变得极其简单。
% Create PeopleDetector object
peopleDetector = vision.PeopleDetector;
% Read your image of question into MATLAB
I = imread('visionteam1.jpg');
% Detect people in your image
[bounding_boxes,scores] = step(peopleDetector,I);
The step(peopleDetector, I)
method returns an M-by-4 matrix defining M bounding boxes, where M represents the number of detected people. Each row of the output matrix, bounding_boxes
, contains a four-element vector, [x y width height]
. This vector specifies, in pixels, the upper-left corner and size, of a bounding box. When no people are detected, the step method returns an empty vector. The input image, I, must be a grayscale or truecolor (RGB) image.
如果您想要此功能允许您检测的每个人的中心位置,您可以执行一些简单的算术:
center_x = x + width / 2;
center_y = y + height / 2;
如何把房间分成很多区域,然后在哪个区域找到一个人的位置。
我在 matlab 中使用背景减法来检测房间里的人,所以我可以扩展这项工作以找出人在图像中的位置,如果我将图像分成多个区域,甚至可以在区域中找出人的位置??
感谢您的帮助 问候
将图像分成几个小节
我在这里提供的方法只是 another Whosebug answer.
的略微修改版本If you want to divide a matrix into submatrices, one way is to use the
mat2cell
function to break the matrix up and store each sub-matrix in a cell of a cell array.
以这个例子为例,一个60x50的矩阵在一个单元格中被分成6个矩阵(如下图所示):
C = mat2cell(I, [10 20 30], [25 25]);
更一般地说,要将您的图像分割成大小相同的 "zones",以下方法可行:
im_rows = 256; % Replace this with the number of rows in your image
im_cols = 256; % Replace this with the number of columns in your image
C = mat2cell(I, [im_rows/2 im_rows/2], [im_cols/2 im_cols/2])
Zone1 = C{1,1};
Zone2 = C{1,2};
Zone3 = C{2,1};
% ... and so on
C
现在是一个 2×2 元胞数组 - 4 "zones" - 每个存储原始图像的四分之一,I
.
检测图像中的人物
现在您已将图像 I
分成几个区域,您可以开始检测每个特定区域内的人。
如果您可以访问 MATLAB 的 vision
包,那么您可以利用 PeopleDetector
object。根据文档,vision
软件包使检测人员变得极其简单。
% Create PeopleDetector object
peopleDetector = vision.PeopleDetector;
% Read your image of question into MATLAB
I = imread('visionteam1.jpg');
% Detect people in your image
[bounding_boxes,scores] = step(peopleDetector,I);
The
step(peopleDetector, I)
method returns an M-by-4 matrix defining M bounding boxes, where M represents the number of detected people. Each row of the output matrix,bounding_boxes
, contains a four-element vector,[x y width height]
. This vector specifies, in pixels, the upper-left corner and size, of a bounding box. When no people are detected, the step method returns an empty vector. The input image, I, must be a grayscale or truecolor (RGB) image.
如果您想要此功能允许您检测的每个人的中心位置,您可以执行一些简单的算术:
center_x = x + width / 2;
center_y = y + height / 2;