Marthee commited on
Commit
385a20e
·
1 Parent(s): b335863

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -382,33 +382,35 @@ def getinnerColor(BlackmaskDetected,img,detectedColors,finalColorArray,num1,num2
382
  countBlackMasks+=1
383
 
384
  return xored,invertedmask , BlackmaskDetected
385
-
386
- def allLevelsofColor(BlackmaskDetected,img,levelonly, invertedmask,color,finalColorArray):
387
- print('ay hagaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
388
  firstLevel=levelonly
389
  firstLevel1=levelonly
390
-
391
  Blackmask = np.zeros(img.shape[:2], dtype="uint8")
392
 
393
  masked,maskedColor,rgbcolor=DetectColor(invertedmask,color)
394
  color=hexRGB(color)
395
-
 
 
396
  pil_image=Image.fromarray(masked)
397
  extrema = pil_image.convert("L").getextrema()
398
  if extrema != (0, 0): # if image is not black --> has a colored mask within
399
 
400
- if rgbcolor.all()==color.all(): #found level tany gowa b nfs el lon
401
-
402
  ColoredContour, Coloredhierarchy = cv2.findContours(masked, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
403
  Coloredhierarchy=Coloredhierarchy[0]
404
  for component in zip(ColoredContour,Coloredhierarchy):
405
  cnt=component[0]
406
  hier=component[1]
407
  area1 = cv2.contourArea(cnt)
408
- if (area1 > 500 ):
409
  if hier[3]> -1:
410
  cv2.drawContours(Blackmask,[cnt],0,(255,255,255), -1)
411
- cv2.drawContours(Blackmask,[cnt],0,(0,0,0), 25)
412
  cv2.drawContours(BlackmaskDetected,[cnt],0,(255,255,255), -1)
413
 
414
  firstLevel=cv2.bitwise_and(invertedmask,invertedmask,mask=Blackmask)
@@ -419,32 +421,36 @@ def allLevelsofColor(BlackmaskDetected,img,levelonly, invertedmask,color,finalCo
419
  (firstLevel[:, :, 1] == 0) &
420
  (firstLevel[:, :, 2] == 0)
421
  )
422
- print('xcvbn')
423
  # set those pixels to white
424
  firstLevel[black_pixels] = [255, 255, 255]
425
  firstLevel1=cv2.bitwise_and(levelonly,firstLevel)
 
426
 
 
427
  for othercolor in finalColorArray:
428
- othercolor=hexRGB(othercolor)
429
- print(othercolor,color )
430
- if [othercolor[0],othercolor[1],othercolor[2]]!=[color[0],color[1],color[2]]:
431
- # print(othercolor.all(),color.all() )
 
432
  masked0=DetectColor(firstLevel,othercolor)[0]
433
  pil_image0=Image.fromarray(masked0)
434
  extrema0 = pil_image0.convert("L").getextrema()
435
- print('jknjfnskjvsjgs')
436
  if extrema != (0, 0): # if image is not black --> has a colored mask within
437
  ColoredContour0, Coloredhierarchy0 = cv2.findContours(masked0, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
438
  for cnt in ColoredContour0:
439
  area1 = cv2.contourArea(cnt)
440
- if (area1 > 500 ):
441
- print('REMOVEDDDDDDDDDDDDDDDDDDDD')
442
  cv2.drawContours(firstLevel1,[cnt],0,(255,255,255), -1)
443
- cv2.drawContours(firstLevel1,[cnt],0,(255,255,255), 20)
444
  cv2.drawContours(BlackmaskDetected,[cnt],0,(0,0,0), -1)
445
-
 
 
 
446
  return firstLevel1, BlackmaskDetected
447
-
448
  def getColoredContour(mask,img,finalColorArray,num1,num2,flag,eachcolor):
449
  print('uuuuuuuuummmmmmmmmmmmm')
450
  ColoredContour, Coloredhierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
 
382
  countBlackMasks+=1
383
 
384
  return xored,invertedmask , BlackmaskDetected
385
+
386
+ def allLevelsofColor(BlackmaskDetected,levelonly, invertedmask,color,finalColorArray):
387
+ # cc=levelonly.copy()
388
  firstLevel=levelonly
389
  firstLevel1=levelonly
390
+ print('in')
391
  Blackmask = np.zeros(img.shape[:2], dtype="uint8")
392
 
393
  masked,maskedColor,rgbcolor=DetectColor(invertedmask,color)
394
  color=hexRGB(color)
395
+ color=[color[0],color[1],color[2]]
396
+ rgbcolor=[rgbcolor[0],rgbcolor[1],rgbcolor[2]]
397
+ print(rgbcolor,color)
398
  pil_image=Image.fromarray(masked)
399
  extrema = pil_image.convert("L").getextrema()
400
  if extrema != (0, 0): # if image is not black --> has a colored mask within
401
 
402
+ if rgbcolor==color: #found level tany gowa b nfs el lon
403
+ print('kkkkkkkk')
404
  ColoredContour, Coloredhierarchy = cv2.findContours(masked, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
405
  Coloredhierarchy=Coloredhierarchy[0]
406
  for component in zip(ColoredContour,Coloredhierarchy):
407
  cnt=component[0]
408
  hier=component[1]
409
  area1 = cv2.contourArea(cnt)
410
+ if (area1 > 1000 ):
411
  if hier[3]> -1:
412
  cv2.drawContours(Blackmask,[cnt],0,(255,255,255), -1)
413
+ cv2.drawContours(Blackmask,[cnt],0,(0,0,0), 20)
414
  cv2.drawContours(BlackmaskDetected,[cnt],0,(255,255,255), -1)
415
 
416
  firstLevel=cv2.bitwise_and(invertedmask,invertedmask,mask=Blackmask)
 
421
  (firstLevel[:, :, 1] == 0) &
422
  (firstLevel[:, :, 2] == 0)
423
  )
424
+
425
  # set those pixels to white
426
  firstLevel[black_pixels] = [255, 255, 255]
427
  firstLevel1=cv2.bitwise_and(levelonly,firstLevel)
428
+ # cv2_imshow(firstLevel1)
429
 
430
+ # cv2_imshow(firstLevel1)
431
  for othercolor in finalColorArray:
432
+ othercolor2=hexRGB(othercolor)
433
+ othercolor2=[othercolor2[0],othercolor2[1],othercolor2[2]]
434
+ print(othercolor2,color)
435
+ if othercolor2!=color:
436
+ print('anothre')
437
  masked0=DetectColor(firstLevel,othercolor)[0]
438
  pil_image0=Image.fromarray(masked0)
439
  extrema0 = pil_image0.convert("L").getextrema()
 
440
  if extrema != (0, 0): # if image is not black --> has a colored mask within
441
  ColoredContour0, Coloredhierarchy0 = cv2.findContours(masked0, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
442
  for cnt in ColoredContour0:
443
  area1 = cv2.contourArea(cnt)
444
+ if (area1 > 1000 ):
 
445
  cv2.drawContours(firstLevel1,[cnt],0,(255,255,255), -1)
446
+ cv2.drawContours(firstLevel1,[cnt],0,(255,255,255), 10)
447
  cv2.drawContours(BlackmaskDetected,[cnt],0,(0,0,0), -1)
448
+ # cv2.drawContours(Blackmask,[cnt],0,(255,255,255), -1)
449
+ # cv2.drawContours(Blackmask,[cnt],0,(255,255,255), 10)
450
+ # cv2_imshow(firstLevel1)
451
+ # cv2_imshow(Blackmask)
452
  return firstLevel1, BlackmaskDetected
453
+
454
  def getColoredContour(mask,img,finalColorArray,num1,num2,flag,eachcolor):
455
  print('uuuuuuuuummmmmmmmmmmmm')
456
  ColoredContour, Coloredhierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)