Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
王雷
/
detection
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 02018e6a
authored
Apr 29, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format
1 parent
82562f90
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
60 deletions
app/src/main/java/com/agenew/detection/MainActivity.java
app/src/main/java/com/agenew/detection/MainActivity.java
View file @
02018e6
...
...
@@ -129,16 +129,13 @@ public class MainActivity extends CameraActivity implements OnImageAvailableList
cropToFrameTransform
=
new
Matrix
();
frameToCropTransform
.
invert
(
cropToFrameTransform
);
trackingOverlay
=
(
OverlayView
)
findViewById
(
R
.
id
.
tracking_overlay
);
trackingOverlay
.
addCallback
(
new
DrawCallback
()
{
@Override
public
void
drawCallback
(
final
Canvas
canvas
)
{
tracker
.
draw
(
canvas
);
if
(
isDebug
())
{
tracker
.
drawDebug
(
canvas
);
}
}
});
trackingOverlay
=
findViewById
(
R
.
id
.
tracking_overlay
);
trackingOverlay
.
addCallback
(
canvas
->
{
tracker
.
draw
(
canvas
);
if
(
isDebug
())
{
tracker
.
drawDebug
(
canvas
);
}
});
tracker
.
setFrameConfiguration
(
previewWidth
,
previewHeight
,
sensorOrientation
);
}
...
...
@@ -232,56 +229,53 @@ public class MainActivity extends CameraActivity implements OnImageAvailableList
ImageUtils
.
saveBitmap
(
croppedBitmap
);
}
runInBackground
(
new
Runnable
()
{
@Override
public
void
run
()
{
LOGGER
.
i
(
"Running detection on image "
+
currTimestamp
);
final
long
startTime
=
SystemClock
.
uptimeMillis
();
final
List
<
Classifier
.
Recognition
>
results
=
detector
.
recognizeImage
(
croppedBitmap
);
lastProcessingTimeMs
=
SystemClock
.
uptimeMillis
()
-
startTime
;
Log
.
e
(
"CHECK"
,
"run: "
+
results
.
size
());
cropCopyBitmap
=
Bitmap
.
createBitmap
(
croppedBitmap
);
final
Canvas
canvas
=
new
Canvas
(
cropCopyBitmap
);
final
Paint
paint
=
new
Paint
();
paint
.
setColor
(
Color
.
RED
);
paint
.
setStyle
(
Style
.
STROKE
);
paint
.
setStrokeWidth
(
2.0f
);
float
minimumConfidence
=
MINIMUM_CONFIDENCE_TF_OD_API
;
switch
(
MODE
)
{
case
TF_OD_API:
minimumConfidence
=
MINIMUM_CONFIDENCE_TF_OD_API
;
break
;
}
final
List
<
Classifier
.
Recognition
>
mappedRecognitions
=
new
LinkedList
<>();
for
(
final
Classifier
.
Recognition
result
:
results
)
{
final
RectF
location
=
result
.
getLocation
();
if
(
location
!=
null
&&
result
.
getConfidence
()
>=
minimumConfidence
)
{
canvas
.
drawRect
(
location
,
paint
);
cropToFrameTransform
.
mapRect
(
location
);
result
.
setLocation
(
location
);
mappedRecognitions
.
add
(
result
);
}
}
tracker
.
trackResults
(
mappedRecognitions
,
currTimestamp
);
trackingOverlay
.
postInvalidate
();
computingDetection
=
false
;
runOnUiThread
(()
->
{
showFrameInfo
(
previewWidth
+
"x"
+
previewHeight
);
showCropInfo
(
cropCopyBitmap
.
getWidth
()
+
"x"
+
cropCopyBitmap
.
getHeight
());
showInference
(
lastProcessingTimeMs
+
"ms"
);
});
}
});
runInBackground
(()
->
{
LOGGER
.
i
(
"Running detection on image "
+
currTimestamp
);
final
long
startTime
=
SystemClock
.
uptimeMillis
();
final
List
<
Classifier
.
Recognition
>
results
=
detector
.
recognizeImage
(
croppedBitmap
);
lastProcessingTimeMs
=
SystemClock
.
uptimeMillis
()
-
startTime
;
Log
.
e
(
"CHECK"
,
"run: "
+
results
.
size
());
cropCopyBitmap
=
Bitmap
.
createBitmap
(
croppedBitmap
);
final
Canvas
canvas1
=
new
Canvas
(
cropCopyBitmap
);
final
Paint
paint
=
new
Paint
();
paint
.
setColor
(
Color
.
RED
);
paint
.
setStyle
(
Style
.
STROKE
);
paint
.
setStrokeWidth
(
2.0f
);
float
minimumConfidence
=
MINIMUM_CONFIDENCE_TF_OD_API
;
switch
(
MODE
)
{
case
TF_OD_API:
minimumConfidence
=
MINIMUM_CONFIDENCE_TF_OD_API
;
break
;
}
final
List
<
Classifier
.
Recognition
>
mappedRecognitions
=
new
LinkedList
<>();
for
(
final
Classifier
.
Recognition
result
:
results
)
{
final
RectF
location
=
result
.
getLocation
();
if
(
location
!=
null
&&
result
.
getConfidence
()
>=
minimumConfidence
)
{
canvas1
.
drawRect
(
location
,
paint
);
cropToFrameTransform
.
mapRect
(
location
);
result
.
setLocation
(
location
);
mappedRecognitions
.
add
(
result
);
}
}
tracker
.
trackResults
(
mappedRecognitions
,
currTimestamp
);
trackingOverlay
.
postInvalidate
();
computingDetection
=
false
;
runOnUiThread
(()
->
{
showFrameInfo
(
previewWidth
+
"x"
+
previewHeight
);
showCropInfo
(
cropCopyBitmap
.
getWidth
()
+
"x"
+
cropCopyBitmap
.
getHeight
());
showInference
(
lastProcessingTimeMs
+
"ms"
);
});
});
}
@Override
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment