@@ -5,7 +5,7 @@ import { Container, Row, Form, Col, Button, ProgressBar, Spinner } from 'react-b
55import UploadedImage from './components/UploadedImge' ;
66import DisplayFoundImages from './components/DisplayFoundImages' ;
77import DisplayCropedImage from './components/DisplayCropedImages' ;
8- import { confirmAlert } from 'react-confirm-alert' ;
8+ import { confirmAlert } from 'react-confirm-alert' ;
99import { NotificationContainer , NotificationManager } from 'react-notifications' ;
1010import ShowBadImages from './components/ShowBadImages' ;
1111import 'react-confirm-alert/src/react-confirm-alert.css' ;
@@ -26,19 +26,25 @@ function App() {
2626 const [ detError , setDetError ] = useState ( [ ] ) ;
2727 const [ showInvalidFiles , setVisibilityInvalidFiles ] = useState ( false ) ;
2828 const [ bigImage , setBigImages ] = useState ( [ ] ) ;
29- const [ loading , setLoading ] = useState ( false )
30-
29+ const [ loading , setLoading ] = useState ( false ) ;
30+
31+ useEffect ( ( ) => {
32+ if ( imageFolder !== null ) {
33+ findImages ( ) ;
34+ }
35+ } , [ imageFolder ] ) ;
36+
3137 const canvasElement = useRef ( null ) ;
3238 const imageElement = useRef ( null ) ;
3339
3440 let server = "http://localhost" ;
35- let port = 8000 ;
41+ let port = 8000 ;
3642
3743 let core = new CompreFace ( server , port ) ;
38-
44+
3945 let recognitionService = core . initFaceRecognitionService ( recognitionKey ) ;
4046 let faceCollection = recognitionService . getFaceCollection ( ) ;
41- let detectionService = core . initFaceDetectionService ( detectionKey )
47+ let detectionService = core . initFaceDetectionService ( detectionKey )
4248
4349 const removeDublicates = ( array ) => {
4450 let tempArray = [ ] ;
@@ -68,12 +74,12 @@ function App() {
6874 setCounter ( 0 )
6975 setRecError ( prevArray => [ ...new Set ( prevArray ) ] )
7076 setVisibilityInvalidFiles ( true ) ;
71-
77+
7278 const reader = new FileReader ( ) ;
7379 reader . onload = myEvent => {
7480 setUploadedImage ( myEvent . target . result )
7581 let sendata = myEvent . target . result . split ( ',' ) [ 1 ] ;
76-
82+
7783 recognitionService . recognize ( sendata , { limit : 10 , prediction_count : 100 , face_plugins : "age,gender" } )
7884 . then ( res => {
7985 setLoading ( false )
@@ -101,7 +107,7 @@ function App() {
101107 }
102108
103109 const onRateChanges = e => {
104- let number = e . target . value ;
110+ let number = e . target . value ;
105111 setFoundFaces ( [ ] ) ;
106112 setRate ( number ) ;
107113
@@ -113,7 +119,7 @@ function App() {
113119 for ( let i = 0 ; i < Object . values ( imageFolder ) . length ; i ++ ) {
114120 if ( subject [ 0 ] === imageFolder [ i ] [ 'name' ] ) setFoundFaces ( oldFaces => [ ...oldFaces , imageFolder [ i ] ] )
115121 }
116- } )
122+ } )
117123 }
118124
119125 const onChangeImageFolder = event => {
@@ -127,15 +133,15 @@ function App() {
127133 return new Promise ( ( resolve , reject ) => {
128134 const reader = new FileReader ( ) ;
129135 reader . readAsDataURL ( file ) ;
130-
136+
131137 reader . onload = ( ) => resolve ( { base64 : reader . result , fileName : file . name } ) ;
132138 reader . onerror = error => reject ( error ) ;
133139 } ) ;
134140 }
135141
136142 const drawFace = ( ctx , aface , index , fileName , lengthOfDetectedFaces , callback , itaration ) => {
137143 ctx . drawImage ( imageElement . current , aface . box . x_min , aface . box . y_min , aface . box . x_max - aface . box . x_min , aface . box . y_max - aface . box . y_min , 0 , 0 , aface . box . x_max - aface . box . x_min , aface . box . y_max - aface . box . y_min ) ;
138-
144+
139145 canvasElement . current . toBlob ( blob => {
140146 faceCollection . add ( blob , fileName )
141147 . then ( data => {
@@ -172,37 +178,37 @@ function App() {
172178 } , 'image/jpeg' , 0.95 )
173179 }
174180
175- const findImages = e => {
181+ const findImages = e => {
176182 setDetError ( [ ] ) ;
177183 setRecError ( [ ] ) ;
178184 setVisibilityInvalidFiles ( false ) ;
179185
180186 let internalCounter = 0 ;
181187
182- const uploadRecursivley = ( intarator ) => {
188+ const uploadRecursivley = ( intarator ) => {
183189 // stop processing at the end of file
184190 if ( ! imageFolder . item ( intarator ) ) {
185191 NotificationManager . success ( "Compeleted!" , "Image processing completed!" , 3000 )
186192 return null ;
187193 }
188-
189- // check size of image
194+
195+ // check size of image
190196 if ( imageFolder . item ( intarator ) . size < 5000000 ) {
191197 // get base64 format of image
192198 getBase64 ( imageFolder . item ( intarator ) )
193199 . then ( customData => {
194200 setPersonsImage ( customData . base64 )
195201 let sendata = customData . base64 . split ( ',' ) [ 1 ] ;
196202 let ctx = canvasElement . current . getContext ( '2d' ) ;
197-
203+
198204 detectionService . detect ( sendata )
199205 . then ( res => {
200206 res . result . forEach ( ( aface , index ) => {
201207 drawFace ( ctx , aface , index , customData . fileName , res . result . length , uploadRecursivley , intarator )
202208 } )
203209 } )
204- . catch ( error => {
205- setDetError ( prevArray => [ ...prevArray , customData . fileName ] )
210+ . catch ( error => {
211+ setDetError ( prevArray => [ ...prevArray , customData . fileName ] )
206212 confirmAlert ( {
207213 title : 'Detection error' ,
208214 message : `Face not found in ${ customData . fileName } ` ,
@@ -266,20 +272,15 @@ function App() {
266272 </ Form . Group >
267273 </ Col >
268274 </ Row >
269- < Row className = "marginTop-15" >
270- < Col >
271- < Button className = "btn btn-primary btn-md float-right" disabled = { ( imageFolder && recognitionKey && detectionKey ) ? false : true } onClick = { findImages } > Upload folder</ Button >
272- </ Col >
273- </ Row >
274275 </ Form >
275276 < Row >
276277 < Col md = { 3 } >
277278 { uploadedImage && < UploadedImage uploadedImage = { uploadedImage } /> }
278279 { showInvalidFiles && < div >
279280 { recError . length && < ShowBadImages data = { recError } badTitle = "Recognition error occured in" /> }
280- { detError . length && < ShowBadImages data = { detError } badTitle = "Detection error occured in" /> }
281- { bigImage . length && < ShowBadImages data = { bigImage } badTitle = "Oversized images" /> }
282- </ div > }
281+ { detError . length && < ShowBadImages data = { detError } badTitle = "Detection error occured in" /> }
282+ { bigImage . length && < ShowBadImages data = { bigImage } badTitle = "Oversized images" /> }
283+ </ div > }
283284 </ Col >
284285 < Col md = { 9 } >
285286 { loading && < div style = { { margin : "20px auto" } } >
@@ -296,11 +297,11 @@ function App() {
296297 < ProgressBar animated now = { ( ( counter + 1 ) / Object . values ( imageFolder ) . length ) * 100 } />
297298 { counter === Object . values ( imageFolder ) . length ? < div >
298299 < span > Done you can select persons image</ span >
299- </ div > : < div > < span > Processing images</ span > </ div > }
300+ </ div > : < div > < span > Processing images</ span > </ div > }
300301 </ Col >
301- </ Row > }
302+ </ Row > }
302303 < Row > { personsImage && < DisplayCropedImage personsImage = { personsImage } imageElement = { imageElement } canvasElement = { canvasElement } /> } </ Row >
303- < NotificationContainer />
304+ < NotificationContainer />
304305 </ Container >
305306 ) ;
306307}
0 commit comments