-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental/threadcall #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Images | ||
#Additional required packages to run this example. | ||
#Pkg.add("Images") | ||
|
||
using AprilTags | ||
|
||
# Simple method to show the image with the tags | ||
function showImage(image, tags) | ||
# Convert image to RGB | ||
imageCol = RGB.(image) | ||
#traw color box on tag corners | ||
foreach(tag->drawTagBox!(imageCol, tag), tags) | ||
imageCol | ||
end | ||
|
||
|
||
## | ||
# Create default detector | ||
detector = AprilTagDetector() | ||
|
||
#Run against a file | ||
image = load(dirname(Base.source_path()) *"/../data/tagtest.jpg") | ||
|
||
@sync begin | ||
starttime = Dates.value(now()) | ||
#call detector in thread | ||
@async global t1 = @timed begin | ||
println("time before detector $(Dates.value(now())-starttime) ms") | ||
global tags = AprilTags.threadcalldetect(detector, image) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# ↑ comment --- compare with this --- uncomment ↓ | ||
# global tags = detector(image) | ||
println("time after detector $(Dates.value(now())-starttime) ms") | ||
|
||
@show length(tags) | ||
end | ||
#carry on doing something else | ||
@async global t2 = @timed begin | ||
println("time starting other $(Dates.value(now())-starttime) ms") | ||
imageCol = load(dirname(Base.source_path()) *"/../data/colortag.jpg") | ||
A = randn(1000,1000) | ||
randsum = sum(A*A') | ||
println("time finished other $(Dates.value(now())-starttime) ms") | ||
@show randsum | ||
end | ||
end | ||
|
||
println("time for detector: $(t1[2]) seconds") | ||
println("time for other: $(t2[2]) seconds") | ||
println() | ||
|
||
showImage(image, tags) | ||
|
||
|
||
|
||
## clean up detector once finished | ||
freeDetector!(detector) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,7 +286,7 @@ mutable struct apriltag_detector | |
nquads::UInt32 | ||
tag_families::Ptr{zarray_t} | ||
wp::Ptr{workerpool_t} | ||
|
||
# mutex::pthread_mutex_t | ||
mutex::NTuple{40, UInt8} | ||
|
||
|
@@ -404,6 +404,18 @@ function apriltag_detector_detect(td, im_orig) | |
ccall((:apriltag_detector_detect, :libapriltag), Ptr{zarray_t}, (Ptr{apriltag_detector_t}, Ptr{image_u8_t}), td, Ref(im_orig)) | ||
end | ||
|
||
""" | ||
threadcall_apriltag_detector_detect(tag_detector, image) | ||
*Experimental* call apriltag_detector_detect in a seperate thread using the experimantal `@threadcall` | ||
Detect tags from an image and return an array of apriltag_detection_t*. | ||
You can use apriltag_detections_destroy to free the array and the detections it contains, or call | ||
detection_destroy and zarray_destroy yourself. | ||
""" | ||
function threadcall_apriltag_detector_detect(td, im_orig) | ||
@threadcall((:apriltag_detector_detect, :libapriltag), Ptr{zarray_t}, (Ptr{apriltag_detector_t}, Ptr{image_u8_t}), td, Ref(im_orig)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as you are not calling back into Julia from the C implementation (which AprilTags is not doing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
|
||
function apriltag_detection_destroy(det) | ||
ccall((:apriltag_detection_destroy, :libapriltag), Void, (Ptr{apriltag_detection_t},), det) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is the right way to do it. Haven't worked with
@threadcall
before but understand from docs that it is non-blocking.