Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-1.1
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-1.1
Commits
8235fe32
Commit
8235fe32
authored
Jun 04, 2008
by
Antoine Cellerier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
YUV 422 Packed motion detect (still kind of broken).
parent
2306ec6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
341 additions
and
148 deletions
+341
-148
modules/video_filter/motiondetect.c
modules/video_filter/motiondetect.c
+341
-148
No files found.
modules/video_filter/motiondetect.c
View file @
8235fe32
/*****************************************************************************
/*****************************************************************************
* motiondetec.c : Second version of a motion detection plugin.
* motiondetec.c : Second version of a motion detection plugin.
*****************************************************************************
*****************************************************************************
* Copyright (C) 2000-200
6
the VideoLAN team
* Copyright (C) 2000-200
8
the VideoLAN team
* $Id$
* $Id$
*
*
* Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
* Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
...
@@ -44,7 +44,12 @@ static int Create ( vlc_object_t * );
...
@@ -44,7 +44,12 @@ static int Create ( vlc_object_t * );
static
void
Destroy
(
vlc_object_t
*
);
static
void
Destroy
(
vlc_object_t
*
);
static
picture_t
*
Filter
(
filter_t
*
,
picture_t
*
);
static
picture_t
*
Filter
(
filter_t
*
,
picture_t
*
);
static
picture_t
*
FilterPacked
(
filter_t
*
,
picture_t
*
);
static
void
GaussianConvolution
(
uint32_t
*
,
uint32_t
*
,
int
,
int
,
int
);
static
void
GaussianConvolution
(
uint32_t
*
,
uint32_t
*
,
int
,
int
,
int
);
static
int
FindShapes
(
uint32_t
*
,
uint32_t
*
,
int
,
int
,
int
,
int
*
,
int
*
,
int
*
,
int
*
,
int
*
);
#define NUM_COLORS 5000
/*****************************************************************************
/*****************************************************************************
* Module descriptor
* Module descriptor
...
@@ -83,10 +88,13 @@ static int Create( vlc_object_t *p_this )
...
@@ -83,10 +88,13 @@ static int Create( vlc_object_t *p_this )
switch
(
p_filter
->
fmt_in
.
video
.
i_chroma
)
switch
(
p_filter
->
fmt_in
.
video
.
i_chroma
)
{
{
CASE_PLANAR_YUV
CASE_PLANAR_YUV
p_filter
->
pf_video_filter
=
Filter
;
break
;
break
;
CASE_PACKED_YUV_422
CASE_PACKED_YUV_422
msg_Err
(
p_filter
,
"FIXME ... this should be easy."
);
p_filter
->
pf_video_filter
=
FilterPacked
;
break
;
default:
default:
msg_Err
(
p_filter
,
"Unsupported input chroma (%4s)"
,
msg_Err
(
p_filter
,
"Unsupported input chroma (%4s)"
,
(
char
*
)
&
(
p_filter
->
fmt_in
.
video
.
i_chroma
)
);
(
char
*
)
&
(
p_filter
->
fmt_in
.
video
.
i_chroma
)
);
...
@@ -101,8 +109,6 @@ static int Create( vlc_object_t *p_this )
...
@@ -101,8 +109,6 @@ static int Create( vlc_object_t *p_this )
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
}
}
p_filter
->
pf_video_filter
=
Filter
;
p_filter
->
p_sys
->
p_oldpix
=
NULL
;
p_filter
->
p_sys
->
p_oldpix
=
NULL
;
p_filter
->
p_sys
->
p_buf
=
NULL
;
p_filter
->
p_sys
->
p_buf
=
NULL
;
...
@@ -126,8 +132,9 @@ static void Destroy( vlc_object_t *p_this )
...
@@ -126,8 +132,9 @@ static void Destroy( vlc_object_t *p_this )
free
(
p_filter
->
p_sys
);
free
(
p_filter
->
p_sys
);
}
}
/*****************************************************************************
/*****************************************************************************
*
Rende
r
*
Filter YUV Plana
r
*****************************************************************************/
*****************************************************************************/
static
picture_t
*
Filter
(
filter_t
*
p_filter
,
picture_t
*
p_inpic
)
static
picture_t
*
Filter
(
filter_t
*
p_filter
,
picture_t
*
p_inpic
)
{
{
...
@@ -156,21 +163,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -156,21 +163,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
if
(
!
p_inpic
)
return
NULL
;
if
(
!
p_inpic
)
return
NULL
;
p_outpic
=
p_filter
->
pf_vout_buffer_new
(
p_filter
);
if
(
!
p_outpic
)
{
msg_Warn
(
p_filter
,
"can't get output picture"
);
if
(
p_inpic
->
pf_release
)
p_inpic
->
pf_release
(
p_inpic
);
return
NULL
;
}
p_outpix
=
p_outpic
->
p
[
Y_PLANE
].
p_pixels
;
vlc_memcpy
(
p_outpic
->
p
[
U_PLANE
].
p_pixels
,
p_inpic
->
p
[
U_PLANE
].
p_pixels
,
p_inpic
->
p
[
U_PLANE
].
i_pitch
*
p_inpic
->
p
[
U_PLANE
].
i_visible_lines
);
vlc_memcpy
(
p_outpic
->
p
[
V_PLANE
].
p_pixels
,
p_inpic
->
p
[
V_PLANE
].
p_pixels
,
p_inpic
->
p
[
V_PLANE
].
i_pitch
*
p_inpic
->
p
[
V_PLANE
].
i_visible_lines
);
if
(
!
p_sys
->
p_oldpix
||
!
p_sys
->
p_buf
)
if
(
!
p_sys
->
p_oldpix
||
!
p_sys
->
p_buf
)
{
{
free
(
p_sys
->
p_oldpix
);
free
(
p_sys
->
p_oldpix
);
...
@@ -180,6 +172,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -180,6 +172,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
p_sys
->
p_oldpix_v
=
malloc
(
i_src_pitch_u
*
i_num_lines_u
);
p_sys
->
p_oldpix_v
=
malloc
(
i_src_pitch_u
*
i_num_lines_u
);
p_sys
->
p_buf
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
);
p_sys
->
p_buf
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
);
p_sys
->
p_buf2
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
);
p_sys
->
p_buf2
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
);
vlc_memcpy
(
p_sys
->
p_oldpix
,
p_inpix
,
i_src_pitch
*
i_num_lines
);
vlc_memcpy
(
p_sys
->
p_oldpix_u
,
p_inpix_u
,
i_src_pitch_u
*
i_num_lines_u
);
vlc_memcpy
(
p_sys
->
p_oldpix_v
,
p_inpix_v
,
i_src_pitch_u
*
i_num_lines_u
);
return
p_inpic
;
return
p_inpic
;
}
}
p_oldpix
=
p_sys
->
p_oldpix
;
p_oldpix
=
p_sys
->
p_oldpix
;
...
@@ -188,6 +183,23 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -188,6 +183,23 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
p_buf
=
p_sys
->
p_buf
;
p_buf
=
p_sys
->
p_buf
;
p_buf2
=
p_sys
->
p_buf2
;
p_buf2
=
p_sys
->
p_buf2
;
p_outpic
=
p_filter
->
pf_vout_buffer_new
(
p_filter
);
if
(
!
p_outpic
)
{
msg_Warn
(
p_filter
,
"can't get output picture"
);
if
(
p_inpic
->
pf_release
)
p_inpic
->
pf_release
(
p_inpic
);
return
NULL
;
}
p_outpix
=
p_outpic
->
p
[
Y_PLANE
].
p_pixels
;
vlc_memcpy
(
p_outpic
->
p
[
Y_PLANE
].
p_pixels
,
p_inpic
->
p
[
Y_PLANE
].
p_pixels
,
p_inpic
->
p
[
Y_PLANE
].
i_pitch
*
p_inpic
->
p
[
Y_PLANE
].
i_visible_lines
);
vlc_memcpy
(
p_outpic
->
p
[
U_PLANE
].
p_pixels
,
p_inpic
->
p
[
U_PLANE
].
p_pixels
,
p_inpic
->
p
[
U_PLANE
].
i_pitch
*
p_inpic
->
p
[
U_PLANE
].
i_visible_lines
);
vlc_memcpy
(
p_outpic
->
p
[
V_PLANE
].
p_pixels
,
p_inpic
->
p
[
V_PLANE
].
p_pixels
,
p_inpic
->
p
[
V_PLANE
].
i_pitch
*
p_inpic
->
p
[
V_PLANE
].
i_visible_lines
);
vlc_mutex_lock
(
&
p_filter
->
p_sys
->
lock
);
vlc_mutex_lock
(
&
p_filter
->
p_sys
->
lock
);
/**
/**
...
@@ -227,7 +239,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -227,7 +239,6 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
break
;
break
;
}
}
//format = 0;
if
(
format
)
if
(
format
)
{
{
for
(
line
=
0
;
line
<
i_num_lines_u
;
line
++
)
for
(
line
=
0
;
line
<
i_num_lines_u
;
line
++
)
...
@@ -271,140 +282,198 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -271,140 +282,198 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
}
}
/**
/**
*
Apply some smoothing to remove noise
*
Get the areas where movement was detected
*/
*/
GaussianConvolution
(
p_buf2
,
p_buf
,
i_src_pitch
,
i_num_lines
,
i_src_visible
);
int
colors
[
NUM_COLORS
];
int
color_x_min
[
NUM_COLORS
];
int
color_x_max
[
NUM_COLORS
];
int
color_y_min
[
NUM_COLORS
];
int
color_y_max
[
NUM_COLORS
];
/**
last
=
FindShapes
(
p_buf2
,
p_buf
,
i_src_pitch
,
i_src_visible
,
i_num_lines
,
* Copy luminance plane
colors
,
color_x_min
,
color_x_max
,
color_y_min
,
color_y_max
);
*/
for
(
i
=
0
;
i
<
i_src_pitch
*
i_num_lines
;
i
++
)
{
p_outpix
[
i
]
=
p_inpix
[
i
];
}
/**
/**
* Label the shapes ans build the labels dependencies list
* Count final number of shapes
* Draw rectangles (there can be more than 1 moving shape in 1 rectangle)
*/
*/
last
=
1
;
j
=
0
;
int
colors
[
5000
];
for
(
i
=
1
;
i
<
last
;
i
++
)
int
color_x_min
[
5000
];
int
color_x_max
[
5000
];
int
color_y_min
[
5000
];
int
color_y_max
[
5000
];
for
(
j
=
0
;
j
<
i_src_pitch
;
j
++
)
{
p_buf
[
j
]
=
0
;
p_buf
[(
i_num_lines
-
1
)
*
i_src_pitch
+
j
]
=
0
;
}
for
(
i
=
1
;
i
<
i_num_lines
-
1
;
i
++
)
{
{
p_buf
[
i
*
i_src_pitch
]
=
0
;
if
(
colors
[
i
]
==
i
&&
color_x_min
[
i
]
!=
-
1
)
for
(
j
=
1
;
j
<
i_src_pitch
-
1
;
j
++
)
{
{
if
(
p_buf
[
i
*
i_src_pitch
+
j
]
>
15
)
if
(
(
color_y_max
[
i
]
-
color_y_min
[
i
]
)
*
(
color_x_max
[
i
]
-
color_x_min
[
i
]
)
<
16
)
continue
;
j
++
;
int
x
,
y
;
y
=
color_y_min
[
i
];
for
(
x
=
color_x_min
[
i
];
x
<=
color_x_max
[
i
];
x
++
)
{
{
if
(
p_buf
[(
i
-
1
)
*
i_src_pitch
+
j
-
1
]
)
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
{
p_buf
[
i
*
i_src_pitch
+
j
]
=
p_buf
[(
i
-
1
)
*
i_src_pitch
+
j
-
1
];
}
else
if
(
p_buf
[(
i
-
1
)
*
i_src_pitch
+
j
]
)
p_buf
[
i
*
i_src_pitch
+
j
]
=
p_buf
[(
i
-
1
)
*
i_src_pitch
+
j
];
else
if
(
p_buf
[
i
*
i_src_pitch
+
j
-
1
]
)
p_buf
[
i
*
i_src_pitch
+
j
]
=
p_buf
[
i
*
i_src_pitch
+
j
-
1
];
else
{
p_buf
[
i
*
i_src_pitch
+
j
]
=
last
;
colors
[
last
]
=
last
;
last
++
;
}
#define CHECK( A ) \
if( p_buf[A] && p_buf[A] != p_buf[i*i_src_pitch+j] ) \
{ \
if( p_buf[A] < p_buf[i*i_src_pitch+j] ) \
colors[p_buf[i*i_src_pitch+j]] = p_buf[A]; \
else \
colors[p_buf[A]] = p_buf[i*i_src_pitch+j]; \
}
CHECK
(
i
*
i_src_pitch
+
j
-
1
);
CHECK
(
(
i
-
1
)
*
i_src_pitch
+
j
-
1
);
CHECK
(
(
i
-
1
)
*
i_src_pitch
+
j
);
CHECK
(
(
i
-
1
)
*
i_src_pitch
+
j
+
1
);
}
}
else
y
=
color_y_max
[
i
];
for
(
x
=
color_x_min
[
i
];
x
<=
color_x_max
[
i
];
x
++
)
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
x
=
color_x_min
[
i
];
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
x
=
color_x_max
[
i
];
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
{
{
p_
buf
[
i
*
i_src_pitch
+
j
]
=
0
;
p_
outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
}
}
}
p_buf
[
i
*
i_src_pitch
+
j
]
=
0
;
}
}
msg_Dbg
(
p_filter
,
"Counted %d moving shapes."
,
j
);
/**
/**
*
Initialise empty rectangle list
*
We're done. Lets keep a copy of the picture
*/
*/
for
(
i
=
1
;
i
<
last
;
i
++
)
vlc_memcpy
(
p_oldpix
,
p_inpix
,
i_src_pitch
*
i_num_lines
);
vlc_memcpy
(
p_oldpix_u
,
p_inpix_u
,
i_src_pitch_u
*
i_num_lines_u
);
vlc_memcpy
(
p_oldpix_v
,
p_inpix_v
,
i_src_pitch_u
*
i_num_lines_u
);
vlc_mutex_unlock
(
&
p_filter
->
p_sys
->
lock
);
return
CopyInfoAndRelease
(
p_outpic
,
p_inpic
);
}
/*****************************************************************************
* Filter YUV Packed
*****************************************************************************/
static
picture_t
*
FilterPacked
(
filter_t
*
p_filter
,
picture_t
*
p_inpic
)
{
picture_t
*
p_outpic
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
int
i_y_offset
,
i_u_offset
,
i_v_offset
;
const
uint8_t
*
p_inpix
;
const
uint8_t
*
p_inpix_u
;
const
uint8_t
*
p_inpix_v
;
int
i_src_pitch
;
int
i_src_visible
;
int
i_num_lines
;
uint8_t
*
p_oldpix
;
uint8_t
*
p_oldpix_u
;
uint8_t
*
p_oldpix_v
;
uint8_t
*
p_outpix
;
uint32_t
*
p_buf
;
uint32_t
*
p_buf2
;
int
i
,
j
;
int
last
;
if
(
GetPackedYuvOffsets
(
p_inpic
->
format
.
i_chroma
,
&
i_y_offset
,
&
i_u_offset
,
&
i_v_offset
)
!=
VLC_SUCCESS
)
{
{
color_x_min
[
i
]
=
-
1
;
msg_Warn
(
p_filter
,
"Unsupported input chroma (%4s)"
,
color_x_max
[
i
]
=
-
1
;
(
char
*
)
&
(
p_inpic
->
format
.
i_chroma
)
);
color_y_min
[
i
]
=
-
1
;
if
(
p_inpic
->
pf_release
)
color_y_max
[
i
]
=
-
1
;
p_inpic
->
pf_release
(
p_inpic
);
return
NULL
;
}
p_inpix
=
p_inpic
->
p
->
p_pixels
+
i_y_offset
;
p_inpix_u
=
p_inpic
->
p
->
p_pixels
+
i_u_offset
;
p_inpix_v
=
p_inpic
->
p
->
p_pixels
+
i_v_offset
;
i_src_pitch
=
p_inpic
->
p
->
i_pitch
;
i_src_visible
=
p_inpic
->
p
->
i_visible_pitch
;
i_num_lines
=
p_inpic
->
p
->
i_visible_lines
;
if
(
!
p_sys
->
p_oldpix
||
!
p_sys
->
p_buf
)
{
free
(
p_sys
->
p_oldpix
);
free
(
p_sys
->
p_buf
);
p_sys
->
p_oldpix
=
malloc
(
i_src_pitch
*
i_num_lines
);
p_sys
->
p_buf
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
/
2
);
p_sys
->
p_buf2
=
malloc
(
sizeof
(
uint32_t
)
*
i_src_pitch
*
i_num_lines
/
2
);
vlc_memcpy
(
p_sys
->
p_oldpix
,
p_inpic
->
p
->
p_pixels
,
i_src_pitch
*
i_num_lines
);
return
p_inpic
;
}
p_outpic
=
p_filter
->
pf_vout_buffer_new
(
p_filter
);
if
(
!
p_outpic
)
{
msg_Warn
(
p_filter
,
"can't get output picture"
);
if
(
p_inpic
->
pf_release
)
p_inpic
->
pf_release
(
p_inpic
);
return
NULL
;
}
}
p_outpix
=
p_outpic
->
p
->
p_pixels
+
i_y_offset
;
vlc_memcpy
(
p_outpic
->
p
->
p_pixels
,
p_inpic
->
p
->
p_pixels
,
p_inpic
->
p
->
i_pitch
*
p_inpic
->
p
->
i_visible_lines
);
p_oldpix
=
p_sys
->
p_oldpix
+
i_y_offset
;
p_oldpix_u
=
p_sys
->
p_oldpix
+
i_u_offset
;
p_oldpix_v
=
p_sys
->
p_oldpix
+
i_v_offset
;
p_buf
=
p_sys
->
p_buf
;
p_buf2
=
p_sys
->
p_buf2
;
vlc_mutex_lock
(
&
p_filter
->
p_sys
->
lock
);
/**
/**
*
Compute rectangle coordinat
es
*
Substract Y plan
es
*/
*/
for
(
i
=
0
;
i
<
i_src_pitch
*
i_num_lines
;
i
+
+
)
for
(
i
=
0
;
i
<
i_src_pitch
*
i_num_lines
;
i
+
=
2
)
{
{
if
(
p_
buf
[
i
]
)
if
(
p_
inpix
[
i
]
>
p_oldpix
[
i
]
)
{
{
while
(
colors
[
p_buf
[
i
]]
!=
p_buf
[
i
]
)
p_buf2
[
i
>>
1
]
=
p_inpix
[
i
]
-
p_oldpix
[
i
];
p_buf
[
i
]
=
colors
[
p_buf
[
i
]];
}
if
(
color_x_min
[
p_buf
[
i
]]
==
-
1
)
else
{
{
color_x_min
[
p_buf
[
i
]]
=
p_buf2
[
i
>>
1
]
=
p_oldpix
[
i
]
-
p_inpix
[
i
];
color_x_max
[
p_buf
[
i
]]
=
i
%
i_src_pitch
;
color_y_min
[
p_buf
[
i
]]
=
color_y_max
[
p_buf
[
i
]]
=
i
/
i_src_pitch
;
}
else
{
int
x
=
i
%
i_src_pitch
,
y
=
i
/
i_src_pitch
;
if
(
x
<
color_x_min
[
p_buf
[
i
]]
)
color_x_min
[
p_buf
[
i
]]
=
x
;
if
(
x
>
color_x_max
[
p_buf
[
i
]]
)
color_x_max
[
p_buf
[
i
]]
=
x
;
if
(
y
<
color_y_min
[
p_buf
[
i
]]
)
color_y_min
[
p_buf
[
i
]]
=
y
;
if
(
y
>
color_y_max
[
p_buf
[
i
]]
)
color_y_max
[
p_buf
[
i
]]
=
y
;
}
}
}
}
}
/**
#if 0
* Merge overlaping rectangles
for( i = 0; i < i_src_pitch * i_num_lines; i+=4 )
*/
for
(
i
=
1
;
i
<
last
;
i
++
)
{
{
if
(
colors
[
i
]
!=
i
)
continue
;
int diff;
if
(
color_x_min
[
i
]
==
-
1
)
continue
;
if( p_inpix_u[i] > p_oldpix_u[i] )
for
(
j
=
i
+
1
;
j
<
last
;
j
++
)
{
{
if
(
colors
[
j
]
!=
j
)
continue
;
diff = p_inpix_u[i] - p_oldpix_u[i];
if
(
color_x_min
[
j
]
==
-
1
)
continue
;
}
if
(
__MAX
(
color_x_min
[
i
],
color_x_min
[
j
]
)
<
__MIN
(
color_x_max
[
i
],
color_x_max
[
j
]
)
&&
else
__MAX
(
color_y_min
[
i
],
color_y_min
[
j
]
)
<
__MIN
(
color_y_max
[
i
],
color_y_max
[
j
]
)
)
{
{
diff = p_oldpix_u[i] - p_inpix_u[i];
color_x_min
[
i
]
=
__MIN
(
color_x_min
[
i
],
color_x_min
[
j
]
);
}
color_x_max
[
i
]
=
__MAX
(
color_x_max
[
i
],
color_x_max
[
j
]
);
if( p_inpix_v[i] > p_oldpix_v[i] )
color_y_min
[
i
]
=
__MIN
(
color_y_min
[
i
],
color_y_min
[
j
]
);
{
color_y_max
[
i
]
=
__MAX
(
color_y_max
[
i
],
color_y_max
[
j
]
);
diff += p_inpix_v[i] - p_oldpix_v[i];
color_x_min
[
j
]
=
-
1
;
j
=
0
;
}
}
}
else
{
diff += p_oldpix_v[i] - p_inpix_v[i];
}
p_buf2[(i>>2)<<1] += diff;
p_buf2[((i>>2)<<1)+1] += diff;
}
}
#endif
/**
* Get the areas where movement was detected
*/
int
colors
[
5000
];
int
color_x_min
[
5000
];
int
color_x_max
[
5000
];
int
color_y_min
[
5000
];
int
color_y_max
[
5000
];
last
=
FindShapes
(
p_buf2
,
p_buf
,
i_src_pitch
/
2
,
i_src_visible
/
2
,
i_num_lines
,
colors
,
color_x_min
,
color_x_max
,
color_y_min
,
color_y_max
);
/**
/**
* Count final number of shapes
* Count final number of shapes
...
@@ -417,23 +486,24 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -417,23 +486,24 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
{
{
if
(
(
color_y_max
[
i
]
-
color_y_min
[
i
]
)
*
(
color_x_max
[
i
]
-
color_x_min
[
i
]
)
<
16
)
continue
;
if
(
(
color_y_max
[
i
]
-
color_y_min
[
i
]
)
*
(
color_x_max
[
i
]
-
color_x_min
[
i
]
)
<
16
)
continue
;
j
++
;
j
++
;
printf
(
"Shape: (%d,%d) (%d,%d)
\n
"
,
color_y_max
[
i
],
color_y_min
[
i
],
color_x_max
[
i
],
color_x_min
[
i
]
);
int
x
,
y
;
int
x
,
y
;
y
=
color_y_min
[
i
];
y
=
color_y_min
[
i
];
for
(
x
=
color_x_min
[
i
]
;
x
<=
color_x_max
[
i
];
x
++
)
for
(
x
=
color_x_min
[
i
]
*
2
;
x
<=
color_x_max
[
i
]
*
2
;
x
+=
2
)
{
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
}
y
=
color_y_max
[
i
];
y
=
color_y_max
[
i
];
for
(
x
=
color_x_min
[
i
]
;
x
<=
color_x_max
[
i
];
x
++
)
for
(
x
=
color_x_min
[
i
]
*
2
;
x
<=
color_x_max
[
i
]
*
2
;
x
+=
2
)
{
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
}
x
=
color_x_min
[
i
];
x
=
color_x_min
[
i
]
*
2
;
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
{
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
}
}
x
=
color_x_max
[
i
];
x
=
color_x_max
[
i
]
*
2
;
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
for
(
y
=
color_y_min
[
i
];
y
<=
color_y_max
[
i
];
y
++
)
{
{
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
p_outpix
[
y
*
i_src_pitch
+
x
]
=
0xff
;
...
@@ -445,23 +515,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
...
@@ -445,23 +515,11 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_inpic )
/**
/**
* We're done. Lets keep a copy of the picture
* We're done. Lets keep a copy of the picture
*/
*/
vlc_memcpy
(
p_oldpix
,
p_inpix
,
i_src_pitch
*
i_num_lines
);
vlc_memcpy
(
p_sys
->
p_oldpix
,
p_inpic
->
p
->
p_pixels
,
i_src_pitch
*
i_num_lines
);
vlc_memcpy
(
p_oldpix_u
,
p_inpix_u
,
i_src_pitch_u
*
i_num_lines_u
);
vlc_memcpy
(
p_oldpix_v
,
p_inpix_v
,
i_src_pitch_u
*
i_num_lines_u
);
vlc_mutex_unlock
(
&
p_filter
->
p_sys
->
lock
);
vlc_mutex_unlock
(
&
p_filter
->
p_sys
->
lock
);
/* misc stuff */
return
CopyInfoAndRelease
(
p_outpic
,
p_inpic
);
p_outpic
->
date
=
p_inpic
->
date
;
p_outpic
->
b_force
=
p_inpic
->
b_force
;
p_outpic
->
i_nb_fields
=
p_inpic
->
i_nb_fields
;
p_outpic
->
b_progressive
=
p_inpic
->
b_progressive
;
p_outpic
->
b_top_field_first
=
p_inpic
->
b_top_field_first
;
if
(
p_inpic
->
pf_release
)
p_inpic
->
pf_release
(
p_inpic
);
return
p_outpic
;
}
}
...
@@ -480,11 +538,6 @@ static void GaussianConvolution( uint32_t *p_inpix, uint32_t *p_smooth,
...
@@ -480,11 +538,6 @@ static void GaussianConvolution( uint32_t *p_inpix, uint32_t *p_smooth,
int
i_src_pitch
,
int
i_num_lines
,
int
i_src_pitch
,
int
i_num_lines
,
int
i_src_visible
)
int
i_src_visible
)
{
{
/* const uint8_t *p_inpix = p_inpic->p[Y_PLANE].p_pixels;
const int i_src_pitch = p_inpic->p[Y_PLANE].i_pitch;
const int i_src_visible = p_inpic->p[Y_PLANE].i_visible_pitch;
const int i_num_lines = p_inpic->p[Y_PLANE].i_visible_lines;*/
int
x
,
y
;
int
x
,
y
;
for
(
y
=
2
;
y
<
i_num_lines
-
2
;
y
++
)
for
(
y
=
2
;
y
<
i_num_lines
-
2
;
y
++
)
{
{
...
@@ -525,3 +578,143 @@ static void GaussianConvolution( uint32_t *p_inpix, uint32_t *p_smooth,
...
@@ -525,3 +578,143 @@ static void GaussianConvolution( uint32_t *p_inpix, uint32_t *p_smooth,
}
}
}
}
}
}
/*****************************************************************************
*
*****************************************************************************/
static
int
FindShapes
(
uint32_t
*
p_diff
,
uint32_t
*
p_smooth
,
int
i_pitch
,
int
i_visible
,
int
i_lines
,
int
*
colors
,
int
*
color_x_min
,
int
*
color_x_max
,
int
*
color_y_min
,
int
*
color_y_max
)
{
int
last
=
1
;
int
i
,
j
;
/**
* Apply some smoothing to remove noise
*/
GaussianConvolution
(
p_diff
,
p_smooth
,
i_pitch
,
i_visible
,
i_lines
);
/**
* Label the shapes and build the labels dependencies list
*/
for
(
j
=
0
;
j
<
i_pitch
;
j
++
)
{
p_smooth
[
j
]
=
0
;
p_smooth
[(
i_lines
-
1
)
*
i_pitch
+
j
]
=
0
;
}
for
(
i
=
1
;
i
<
i_lines
-
1
;
i
++
)
{
p_smooth
[
i
*
i_pitch
]
=
0
;
for
(
j
=
1
;
j
<
i_pitch
-
1
;
j
++
)
{
if
(
p_smooth
[
i
*
i_pitch
+
j
]
>
15
)
{
if
(
p_smooth
[(
i
-
1
)
*
i_pitch
+
j
-
1
]
)
{
p_smooth
[
i
*
i_pitch
+
j
]
=
p_smooth
[(
i
-
1
)
*
i_pitch
+
j
-
1
];
}
else
if
(
p_smooth
[(
i
-
1
)
*
i_pitch
+
j
]
)
p_smooth
[
i
*
i_pitch
+
j
]
=
p_smooth
[(
i
-
1
)
*
i_pitch
+
j
];
else
if
(
p_smooth
[
i
*
i_pitch
+
j
-
1
]
)
p_smooth
[
i
*
i_pitch
+
j
]
=
p_smooth
[
i
*
i_pitch
+
j
-
1
];
else
{
if
(
last
<
5000
)
{
p_smooth
[
i
*
i_pitch
+
j
]
=
last
;
colors
[
last
]
=
last
;
last
++
;
}
}
#define CHECK( A ) \
if( p_smooth[A] && p_smooth[A] != p_smooth[i*i_pitch+j] ) \
{ \
if( p_smooth[A] < p_smooth[i*i_pitch+j] ) \
colors[p_smooth[i*i_pitch+j]] = p_smooth[A]; \
else \
colors[p_smooth[A]] = p_smooth[i*i_pitch+j]; \
}
CHECK
(
i
*
i_pitch
+
j
-
1
);
CHECK
(
(
i
-
1
)
*
i_pitch
+
j
-
1
);
CHECK
(
(
i
-
1
)
*
i_pitch
+
j
);
CHECK
(
(
i
-
1
)
*
i_pitch
+
j
+
1
);
#undef CHECK
}
else
{
p_smooth
[
i
*
i_pitch
+
j
]
=
0
;
}
}
p_smooth
[
i
*
i_pitch
+
j
]
=
0
;
}
/**
* Initialise empty rectangle list
*/
for
(
i
=
1
;
i
<
last
;
i
++
)
{
color_x_min
[
i
]
=
-
1
;
color_x_max
[
i
]
=
-
1
;
color_y_min
[
i
]
=
-
1
;
color_y_max
[
i
]
=
-
1
;
}
/**
* Compute rectangle coordinates
*/
for
(
i
=
0
;
i
<
i_pitch
*
i_lines
;
i
++
)
{
if
(
p_smooth
[
i
]
)
{
while
(
colors
[
p_smooth
[
i
]]
!=
(
int
)
p_smooth
[
i
]
)
p_smooth
[
i
]
=
colors
[
p_smooth
[
i
]];
if
(
color_x_min
[
p_smooth
[
i
]]
==
-
1
)
{
color_x_min
[
p_smooth
[
i
]]
=
color_x_max
[
p_smooth
[
i
]]
=
i
%
i_pitch
;
color_y_min
[
p_smooth
[
i
]]
=
color_y_max
[
p_smooth
[
i
]]
=
i
/
i_pitch
;
}
else
{
int
x
=
i
%
i_pitch
,
y
=
i
/
i_pitch
;
if
(
x
<
color_x_min
[
p_smooth
[
i
]]
)
color_x_min
[
p_smooth
[
i
]]
=
x
;
if
(
x
>
color_x_max
[
p_smooth
[
i
]]
)
color_x_max
[
p_smooth
[
i
]]
=
x
;
if
(
y
<
color_y_min
[
p_smooth
[
i
]]
)
color_y_min
[
p_smooth
[
i
]]
=
y
;
if
(
y
>
color_y_max
[
p_smooth
[
i
]]
)
color_y_max
[
p_smooth
[
i
]]
=
y
;
}
}
}
/**
* Merge overlaping rectangles
*/
for
(
i
=
1
;
i
<
last
;
i
++
)
{
if
(
colors
[
i
]
!=
i
)
continue
;
if
(
color_x_min
[
i
]
==
-
1
)
continue
;
for
(
j
=
i
+
1
;
j
<
last
;
j
++
)
{
if
(
colors
[
j
]
!=
j
)
continue
;
if
(
color_x_min
[
j
]
==
-
1
)
continue
;
if
(
__MAX
(
color_x_min
[
i
],
color_x_min
[
j
]
)
<
__MIN
(
color_x_max
[
i
],
color_x_max
[
j
]
)
&&
__MAX
(
color_y_min
[
i
],
color_y_min
[
j
]
)
<
__MIN
(
color_y_max
[
i
],
color_y_max
[
j
]
)
)
{
color_x_min
[
i
]
=
__MIN
(
color_x_min
[
i
],
color_x_min
[
j
]
);
color_x_max
[
i
]
=
__MAX
(
color_x_max
[
i
],
color_x_max
[
j
]
);
color_y_min
[
i
]
=
__MIN
(
color_y_min
[
i
],
color_y_min
[
j
]
);
color_y_max
[
i
]
=
__MAX
(
color_y_max
[
i
],
color_y_max
[
j
]
);
color_x_min
[
j
]
=
-
1
;
j
=
0
;
}
}
}
return
last
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment