Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
active_learning_pipeline
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sikhin.vc
active_learning_pipeline
Commits
fd1d6fc4
Commit
fd1d6fc4
authored
Mar 03, 2023
by
sikhin.vc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
95f70568
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
sanity_check.py
sanity_check.py
+82
-0
No files found.
sanity_check.py
0 → 100644
View file @
fd1d6fc4
# importing OpenCV
import
cv2
class
SanityCheck
():
"""Class to check presence of cement bag using motion detection"""
def
__init__
(
self
,
frame_batch
):
self
.
data_batch
=
frame_batch
# Assigning our static_back to None
self
.
static_back
=
None
# List when any moving object appear
self
.
motion_list
=
[
None
,
None
]
# Time of movement
self
.
time
=
[]
self
.
sanity_check_status
=
False
def
sanity_check
(
self
):
for
frame
in
self
.
data_batch
:
# Reading frame(image) from video
# check, frame = video.read()
# Initializing motion = 0(no motion)
motion
=
0
# Converting color image to gray_scale image
gray
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2GRAY
)
# Converting gray scale image to GaussianBlur
# so that change can be find easily
gray
=
cv2
.
GaussianBlur
(
gray
,
(
21
,
21
),
0
)
# In first iteration we assign the value
# of static_back to our first frame
if
self
.
static_back
is
None
:
self
.
static_back
=
gray
continue
# Difference between static background
# and current frame(which is GaussianBlur)
diff_frame
=
cv2
.
absdiff
(
self
.
static_back
,
gray
)
# If change in between static background and
# current frame is greater than 30 it will show white color(255)
thresh_frame
=
cv2
.
threshold
(
diff_frame
,
30
,
255
,
cv2
.
THRESH_BINARY
)[
1
]
thresh_frame
=
cv2
.
dilate
(
thresh_frame
,
None
,
iterations
=
2
)
# Finding contour of moving object
cnts
,
_
=
cv2
.
findContours
(
thresh_frame
.
copy
(),
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
for
contour
in
cnts
:
if
cv2
.
contourArea
(
contour
)
<
10000
:
self
.
sanity_check_status
=
False
continue
self
.
sanity_check_status
=
True
self
.
static_back
=
gray
return
self
.
sanity_check_status
arr
=
[]
# Capturing video
video
=
cv2
.
VideoCapture
(
r"C:\Users\sikhin.vc\Downloads\GOLD\OLD_MRP_CAMERA\2021-12-25_11-10-00.mp4"
)
count
=
0
# Infinite while loop to treat stack of image as video
while
True
:
# Reading frame(image) from video
check
,
frame
=
video
.
read
()
print
(
type
(
frame
))
arr
.
append
(
frame
)
count
+=
1
if
(
count
==
10
):
break
s
=
SanityCheck
(
frame_batch
=
arr
)
status
=
s
.
sanity_check
()
print
(
status
)
\ No newline at end of file
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