Summary of the invention
The present invention will overcome the disadvantages mentioned above of the prior art, provide a kind of multi-cam real-time detection side based on multithreadingMethod.
For real-time purpose to be realized, the present invention devises a kind of multi-cam real-time detection side based on multithreadingMethod can effectively improve the requirement of real-time, the precision that reduction recognition of face and pedestrian identify again.This is for real-time meshMark detection, is a very big promotion in efficiency, utilizable because the quantity of same time-triggered protocol camera increasesInformation is also more with time-varying, and it is accurate that user also can judge to detect whether from more information.
The present invention realizes technical solution used by foregoing invention purpose are as follows:
A kind of multi-cam method of real-time of multithreading, comprising the following steps:
Step 1. load pedestrian identifies network again: using the ResNet50 network of pre-training, will connect entirely in ResNet50Output before layer uses triple loss function tectonic networks as pedestrian's feature, and passes through the training of Market1501 data set.
Step 2. establishes face database, loads recognition of face network: selecting the third party library dlib of Python, and face_Recognition carries out the judgement of recognition of face, and the face picture that will test target is added to local library and carries out feature extraction.
Step 3. reads monitoring camera video: monitoring camera mostly uses greatly wired form to be configured, and usually takesIt is loaded with Rstp agreement, carries out video reading using the VideoCapture function in Opencv.
Step 4. personage cuts step: the Yolo3 weight of pre-download is put under specified directory, Yolo3 network is loaded, it willThe picture read from camera is put into Yolo3, obtains the coordinate of pedestrian, and cut out pedestrian's picture and identify.
Step 5. constructs the step of multithreading frame: the multithreading library multiprocess for selecting Python included, and setsSet the picture that multiple queues are used to store multiple cameras (quantity depends on camera quantity).And by main programProcess.start () function starts multithreading service.And daemon finger daemon is used, guarantee that it, in running background, is moreThread comes with being environmentally isolated before operation, guarantees the operation of parent process.
Step 6. person detecting step: in single subprocess, the knowledge of personage is carried out using the target detection network of Yolo3Not, the picture cut is put into the face detection module of face_recoginition and has detected whether clear face, such asFruit can carry out recognition of face if having face, in the case where no face, if someone in pedestrian library, and progressMatch, if there is being matched to people (Euclidean distance is less than threshold value), then identifies successfully and outline personage to add label, if do not hadThe people being matched to can not then judge;If the nobody of pedestrian library, it can not judge
Compared with prior art, have the advantages of technical solution of the present invention:
(1) present invention makes full use of computer memory space, can handle multiple cameras as far as possible, promotes work effectRate, and reduce cost.
(2) third party library carried using Python itself has transplanting convenient, the advantages of should be readily appreciated that.
Specific embodiment
Understand for the ease of those of ordinary skill in the art and implement the present invention, with reference to the accompanying drawings and examples to this hairIt is bright to be described in further detail.
A kind of multi-cam real-time detection method based on multithreading contains step:
(1) pedestrian that load was trained identifies network again
Step 11: selecting existing pedestrian to identify network again, have on current some open source websites in Market1501 dataThe accuracy for having reached 94% on collection, is substantially able to satisfy demand.The structure of the network of selection is as described below, ResNet50 conductLast full articulamentum is removed, and handled 3 block once by backbone network, and res5a, res5b do pondization processing,And the feature vector of one 1024 dimension is obtained by exporting the full articulamentum tieed up for 1024 after the splicing of left and right, while doing to res5cPondization processing, is directly launched into the feature vector of 2048 dimensions.The two are superimposed and is used as final feature vector.
Step 12: add triple loss functions, be added hard_triplet loss function, softmax loss function andRing loss function is built into last pedestrian and identifies network again.The data set of oneself can be finely adjusted, be had reached more preferableEffect.
(2) face database is established, and loads human face recognition model
Step 21: each 2-3 positive face photos of taking one's hat off of example storage, wherein photo is preferably without any processing, otherwiseIt will affect precision.It is stored in a file then according to naming rule, if Li Ming reference numeral is 0003, then photo is namedFor the photo sequence that 0003_*.jpg, * are this example face.
Step 22: dlib and face_recognition third party library being installed in the environment, and can be first by face databaseFace picture pass through feature vector save.
(3) camera head monitor picture step is read
Step 31: the reading of camera video is carried out using the VideoCapture class in Opencv.It will be assisted with RTSPThe user name of camera is discussed, password and IP address define respectively, and are filled according to specified format, and each company is taken the photographAs head is all different.
Step 32: the picture in VideoCapture class being read out using read () function in Opencv, is providedWe are handled.
(4) person detecting step
Step 41: the Yolo3 weight of pre-download being put under specified directory, Yolo3 is a kind of mesh that occupied space is lessMark detection neural network, accuracy rate is low compared to Faster-Rcnn, but uses enough.
Step 42: the picture read from camera is put into Yolo3, obtains the coordinate of pedestrian by load Yolo3 network,And it cuts out pedestrian's picture and identifies.
(5) the step of constructing multithreading frame
Step 51: the load Python included library Multiprocess, and multiple queues are set, number and desired readingThe quantity of camera video is identical, and capacity is set as 2.
Step 52: camera picture is read and is pressed into queue by two queue operations of setting, operation of bringing up the rear, dequeue operationPicture is extruded from queue, and is handled.
Step 53: each sub thread identifies the pedestrian loaded before again and Yolo3 network reads and carries out independent pointAnalysis carrys out parallel work-flow with this, promotes processing speed.
(6) person detecting step:
Step 61: after the picture of camera is read by RSTP protocol remote first, in single subprocess, usingThe target detection network of Yolo3 carries out the identification of personage, and is cut personage by the coordinate that Yolo3 is exported.
Step 62: the picture cut being put into the face detection module of face_recoginition and is detected whetherThere is clear face, recognition of face can be carried out if there is face, step 3 is jumped into if without face.Carry out face knowledgeIf capableing of the information (reaching under threshold value) of very determining pedestrian when other, current information is charged in pedestrian library.
Step 63: in the case where no face, be first the case where seeing pedestrian library, if someone in pedestrian library,It is then matched, if there is being matched to people (Euclidean distance be less than threshold value), then identifies successfully and outline personage to add label,If the people being not matched to can not judge.If the nobody of pedestrian library, it can not judge.
Content described in this specification embodiment is only enumerating to the way of realization of inventive concept, protection of the inventionRange should not be construed as being limited to the specific forms stated in the embodiments, and protection scope of the present invention is also and in art technologyPersonnel conceive according to the present invention it is conceivable that equivalent technologies mean.