Skip to content

Commit

Permalink
change in flippy bird game
Browse files Browse the repository at this point in the history
  • Loading branch information
AKmahim committed Oct 16, 2024
1 parent 150e4ff commit fe9701f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
Binary file not shown.
61 changes: 50 additions & 11 deletions Docs_scanner_using_python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,58 @@
edged = cv2.Canny(blurred,30,50)
#cv2.imshow("Canny",edged)

image,contours,hierarchy = cv2.findContours(edged,cv2.RETR_LIST,cv2.CHAIN_APPROX_NONE)
contours = sorted(contours,key=cv2.contourArea,reverse=True)
image, contours = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

for c in contours:
p = cv2.arcLength(c,True)
approx = cv2.approxPolyDP(c,0.02*p,True)
print(f"Total number of contours found: {len(contours)}")

valid_contours = []
for i, c in enumerate(contours):
print(f"Examining contour {i}")

# Check if the contour has any points
if len(c) == 0:
print(f"Contour {i} is empty")
continue

# Try to calculate the area
try:
area = cv2.contourArea(c)
print(f"Contour {i} area: {area}")

# Check if the area is valid
if area > 10000: # Adjust this threshold as needed
valid_contours.append((area, c))
else:
print(f"Contour {i} has too small area")
except cv2.error as e:
print(f"Error calculating area for contour {i}: {e}")

print(f"Number of valid contours found: {len(valid_contours)}")
contours = sorted(valid_contours, key=lambda x: x[0], reverse=True)

if len(contours) > 0:
# Get the largest contour
_, largest_contour = contours[0]

# Approximate the polygon
p = cv2.arcLength(largest_contour,True)
approx = cv2.approxPolyDP(largest_contour,0.02*p,True)

# Check if it's a quadrilateral
if len(approx) == 4:
target = approx
break
approx = mapper.mapp(target)
print("Found a quadrilateral contour")

# Apply perspective transform
approx = mapper.mapp(target)
pts= np.float32([[0,0],[800,0],[800,800],[0,800]])
op = cv2.getPerspectiveTransform(approx,pts)
dst = cv2.warpPerspective(orig,op,(800,800))
cv2.imshow("Scanned final",dst)
else:
print(f"Found contour with {len(approx)} sides")
else:
print("No valid contours found")

pts= np.float32([[0,0],[800,0],[800,800],[0,800]])
op = cv2.getPerspectiveTransform(approx,pts)
dst = cv2.warpPerspective(orig,op,(800,800))
cv2.imshow("Scanned final",dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
2 changes: 1 addition & 1 deletion Flippy bird/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pygame
import random #using to create random number
import sys
import pygame.locals import * #pygame normal input
import pygame.locals import *

#some global variables
FPS = 32
Expand Down
1 change: 1 addition & 0 deletions PDF_splitter_using_Flask_Python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf
Binary file not shown.

0 comments on commit fe9701f

Please sign in to comment.