face.service.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const psqlDB = require("../psql.service");
  2. class FaceService{
  3. async getSameReportList(feat68,limit){
  4. limit = limit || 10;
  5. // cosine_similarity
  6. let sql = `
  7. select "objectId" as id,"title","photo","createdAt", array_agg(item)::vector(128) <=> $1::vector(128) as cos
  8. from (
  9. SELECT *, jsonb_array_elements("feat68")::float AS item from (
  10. SELECT "objectId","photo","title","feat68","createdAt"
  11. FROM "FaceReport"
  12. WHERE "feat68" is not null
  13. ORDER BY "createdAt" DESC
  14. ) as rt1
  15. ) as rt
  16. GROUP BY "objectId","title",rt."photo","createdAt"
  17. ORDER BY cos limit ${limit};
  18. `
  19. let params = [feat68]
  20. let result
  21. try{
  22. result = await psqlDB.any(sql,params)
  23. console.log(result)
  24. }catch(err){
  25. console.error(err)
  26. }
  27. // 人物不同 0.08 0.09 0.06 0.059
  28. // 人物不同 长相像 0.046 0.045 0.043 0.039
  29. // 人物相同 仰角/光照有变化 0.03846
  30. // 人物相同 > 0.0214 0.0188 0.00218 0.038 0.023
  31. // result = result.filter(item=>item.cos<0.0385 && item.id!=report.id)
  32. // result.sort((a,b)=>a.createdAt-b.createdAt)
  33. if(result?.length>0){
  34. console.log(result)
  35. }
  36. return result
  37. }
  38. }
  39. module.exports.FaceService = FaceService