vendor: OpenCV 5.0.0 snapshot at 755e50675d97db9b7d449d8bd6b09888646f6c6e
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using OpenCV
|
||||
|
||||
const cv = OpenCV
|
||||
|
||||
|
||||
# chess1.png is at https://raw.githubusercontent.com/opencv/opencv_extra/master/testdata/cv/cameracalibration/chess1.png
|
||||
img = cv.imread("chess1.png",cv.IMREAD_GRAYSCALE)
|
||||
climg = cv.cvtColor(img, cv.COLOR_GRAY2BGR)
|
||||
|
||||
# Find the chess board corners
|
||||
ret, corners = cv.findChessboardCorners(img, cv.Size{Int32}(7,5))
|
||||
|
||||
# If found, add object points, image points (after refining them)
|
||||
if ret
|
||||
climg = cv.drawChessboardCorners(climg, cv.Size{Int32}(7,5), corners,ret)
|
||||
cv.imshow("img",climg)
|
||||
cv.waitKey(Int32(0))
|
||||
|
||||
cv.destroyAllWindows()
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
using OpenCV
|
||||
|
||||
function detect(img::OpenCV.InputArray, cascade)
|
||||
rects = OpenCV.detectMultiScale(cascade, img, scaleFactor=1.3, minNeighbors=Int32(4), minSize=OpenCV.Size{Int32}(30, 30), flags=OpenCV.CASCADE_SCALE_IMAGE)
|
||||
processed_rects = []
|
||||
for rect in rects
|
||||
push!(processed_rects, (rect.x, rect.y, rect.width+rect.x, rect.height+rect.y))
|
||||
end
|
||||
return processed_rects
|
||||
end
|
||||
|
||||
function draw_rects(img, rects, color)
|
||||
for x in rects
|
||||
OpenCV.rectangle(img, OpenCV.Point{Int32}(x[1], x[2]), OpenCV.Point{Int32}(x[3], x[4]), color, thickness = Int32(2))
|
||||
end
|
||||
end
|
||||
|
||||
cap = OpenCV.VideoCapture(Int32(0))
|
||||
|
||||
# Replace the paths for the classifiers before running
|
||||
|
||||
cascade = OpenCV.CascadeClassifier("haarcascade_frontalface_alt.xml")
|
||||
nested = OpenCV.CascadeClassifier("haarcascade_eye.xml")
|
||||
|
||||
OpenCV.namedWindow("facedetect")
|
||||
|
||||
while true
|
||||
ret, img = OpenCV.read(cap)
|
||||
if ret==false
|
||||
print("Webcam stopped")
|
||||
break
|
||||
end
|
||||
gray = OpenCV.cvtColor(img, OpenCV.COLOR_BGR2GRAY)
|
||||
gray = OpenCV.equalizeHist(gray)
|
||||
|
||||
rects = detect(gray, cascade)
|
||||
vis = copy(img)
|
||||
draw_rects(vis, rects, (0.0, 255.0, 0.0))
|
||||
|
||||
if ~OpenCV.empty(nested)
|
||||
for x in rects
|
||||
roi = view(gray, :, Int(x[1]):Int(x[3]), Int(x[2]):Int(x[4]))
|
||||
subrects = detect(roi, nested)
|
||||
draw_view = view(vis, :, Int(x[1]):Int(x[3]), Int(x[2]):Int(x[4]))
|
||||
draw_rects(draw_view, subrects, (255.0, 0.0, 0.0))
|
||||
end
|
||||
end
|
||||
|
||||
OpenCV.imshow("facedetect", vis)
|
||||
if OpenCV.waitKey(Int32(5))==27
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
OpenCV.release(cap)
|
||||
|
||||
OpenCV.destroyAllWindows()
|
||||
|
||||
print("Stopped")
|
||||
@@ -0,0 +1,39 @@
|
||||
using OpenCV
|
||||
const cv = OpenCV
|
||||
size0 = Int32(300)
|
||||
# take the model from https://github.com/opencv/opencv_extra/tree/master/testdata/dnn
|
||||
net = cv.dnn_DetectionModel("opencv_face_detector.pbtxt", "opencv_face_detector_uint8.pb")
|
||||
|
||||
cv.dnn.setPreferableTarget(net, cv.dnn.DNN_TARGET_CPU)
|
||||
cv.dnn.setInputMean(net, (104, 177, 123))
|
||||
cv.dnn.setInputScale(net, 1.)
|
||||
cv.dnn.setInputSize(net, size0, size0)
|
||||
|
||||
cap = cv.VideoCapture(Int32(0))
|
||||
while true
|
||||
ok, frame = cv.read(cap)
|
||||
if ok == false
|
||||
break
|
||||
end
|
||||
classIds, confidences, boxes = cv.dnn.detect(net, frame, confThreshold=Float32(0.5))
|
||||
|
||||
for i in 1:size(boxes,1)
|
||||
confidence = confidences[i]
|
||||
x0 = Int32(boxes[i].x)
|
||||
y0 = Int32(boxes[i].y)
|
||||
x1 = Int32(boxes[i].x+boxes[i].width)
|
||||
y1 = Int32(boxes[i].y+boxes[i].height)
|
||||
cv.rectangle(frame, cv.Point{Int32}(x0, y0), cv.Point{Int32}(x1, y1), (100, 255, 100); thickness = Int32(5))
|
||||
label = "face: " * string(confidence)
|
||||
lsize, bl = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, Int32(1))
|
||||
cv.rectangle(frame, cv.Point{Int32}(x0,y0), cv.Point{Int32}(x0+lsize.width, y0+lsize.height+bl), (100,255,100); thickness = Int32(-1))
|
||||
cv.putText(frame, label, cv.Point{Int32}(x0, y0 + lsize.height),
|
||||
cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0); thickness = Int32(1), lineType = cv.LINE_AA)
|
||||
end
|
||||
|
||||
|
||||
cv.imshow("detections", frame)
|
||||
if cv.waitKey(Int32(30)) >= 0
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
using OpenCV
|
||||
const cv = OpenCV
|
||||
|
||||
img = rand(UInt8, 3, 500, 500)
|
||||
filter = rand(Float32, 1, 5, 5)/25
|
||||
|
||||
out = OpenCV.filter2D(img, Int32(-1), filter)
|
||||
|
||||
cv.namedWindow("orig")
|
||||
cv.namedWindow("out")
|
||||
|
||||
cv.imshow("orig", img)
|
||||
cv.imshow("out", out)
|
||||
|
||||
cv.waitKey(Int32(0))
|
||||
@@ -0,0 +1,29 @@
|
||||
using OpenCV
|
||||
|
||||
println("")
|
||||
println("This is a simple exmample demonstrating the use of SimpleBlobDetector")
|
||||
println("")
|
||||
print("Path to image: ")
|
||||
img_dir = readline()
|
||||
|
||||
img = OpenCV.imread(img_dir)
|
||||
img_gray = OpenCV.cvtColor(img, OpenCV.COLOR_BGR2GRAY)
|
||||
|
||||
OpenCV.namedWindow("Img - Color")
|
||||
OpenCV.namedWindow("Img - Gray")
|
||||
|
||||
|
||||
OpenCV.imshow("Img - Color", img)
|
||||
OpenCV.imshow("Img - Gray", img_gray)
|
||||
|
||||
OpenCV.waitKey(Int32(0))
|
||||
|
||||
OpenCV.destroyAllWindows()
|
||||
|
||||
detector = OpenCV.SimpleBlobDetector_create()
|
||||
kps = OpenCV.detect(detector, img_gray)
|
||||
|
||||
println("Number of keypoints: ", size(kps))
|
||||
for kp in kps
|
||||
println(kp.pt, "\t", kp.size)
|
||||
end
|
||||
Reference in New Issue
Block a user