# REPL
using VideoIO
using Images
using LSHFunctions
frms = Vector{UInt64}(undef, 25000);
hashfn = LSHFunction(cossim, 64);
function one_pixes(x::Matrix{RGB{Float32}})::Bool
pix = x[1,1]
for x_el in x
if x_el != pix return false; end
end
return true
end
function frmkeyb(hfn::SimHash{Float32}, im::PermutedDimsArray{RGB{N0f8}, 2, (2, 1), (2, 1), Matrix{RGB{N0f8}}})::UInt64
# @show typeof(im)
h,w = size(im)
im = im[h÷8:h*7÷8, w÷8:w*7÷8]
h, w = size(im)
h ÷= 20
w ÷= 20
resized = [RGB{Float32}(sum(im[i:i+h-1, j:j+w-1])/(h*w))
for (i,j) in Iterators.product(1:h:size(im)[1]-h+1, 1:w:size(im)[2]-w+1)]
one_pixes(resized) ? zero(UInt64) : reduce((x, y)->(UInt64(x) <<1 ) | UInt64(y), hfn(reshape(rawview(channelview(resized)), :)))
end
res(hashfn, video_path::String) = VideoIO.openvideo(video_path, thread_count=1) do vr
img = read(vr);
frms[1] = frmkeyb(hashfn, img)
cnt = 1
while !eof(vr)
cnt += 1
read!(vr, img);
frms[cnt] = frmkeyb(hashfn, img);
end
(0x0032, copy(frms[1:cnt-25]))
end;
@time res(hashfn, "https://adxvideo.dataeye.com/6961/1f7a48d541dd71c5025f119a9fe7ddd9.mp4");
Now, In my pc, it output as follows
5.338815 seconds (3.15 M allocations: 2.664 GiB, 1.62% gc time, 0.84% compilation time)