Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,14 +59,24 @@ crop=st.checkbox("Crop")
|
|
| 59 |
|
| 60 |
btn=st.button("Submit")
|
| 61 |
|
| 62 |
-
def
|
| 63 |
tx=30 #np.random.randint(2,60)
|
| 64 |
ty=45 #np.random.randint(2,55)
|
| 65 |
tm=np.array([[1,0,tx],[0,1,ty]],dtype=np.float32)
|
| 66 |
-
trans_img=cv2.warpAffine(img,tm,dsize=(img.shape[1],img.shape[0]))
|
| 67 |
img_rgb = cv2.cvtColor(trans_img, cv2.COLOR_BGR2RGB)
|
| 68 |
st.image(img_rgb, caption="Translation Applied", use_container_width=True)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
if uploaded_file is not None:
|
| 72 |
# Converting the image into array
|
|
@@ -77,7 +87,7 @@ if uploaded_file is not None:
|
|
| 77 |
# img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 78 |
transformation = []
|
| 79 |
if trans:
|
| 80 |
-
|
| 81 |
transformation.append("Translation")
|
| 82 |
if rot:
|
| 83 |
transformation.append("Rotation")
|
|
|
|
| 59 |
|
| 60 |
btn=st.button("Submit")
|
| 61 |
|
| 62 |
+
def translation(img):
|
| 63 |
tx=30 #np.random.randint(2,60)
|
| 64 |
ty=45 #np.random.randint(2,55)
|
| 65 |
tm=np.array([[1,0,tx],[0,1,ty]],dtype=np.float32)
|
| 66 |
+
trans_img=cv2.warpAffine(img,tm,dsize=(img.shape[1],img.shape[0]),borderMode=cv2.BORDER_REFLECT)
|
| 67 |
img_rgb = cv2.cvtColor(trans_img, cv2.COLOR_BGR2RGB)
|
| 68 |
st.image(img_rgb, caption="Translation Applied", use_container_width=True)
|
| 69 |
|
| 70 |
+
def rotation(img):
|
| 71 |
+
#center = (width//2, height//2)
|
| 72 |
+
angle=90
|
| 73 |
+
r_x=img.shape[0]//2
|
| 74 |
+
r_y=img.shape[1]//2
|
| 75 |
+
rm=cv2.getRotationMatrix2D((r_y,r_x),angle,1)
|
| 76 |
+
r_img=cv2.warpAffine(img,rm,(img.shape[1],img.shape[0]))
|
| 77 |
+
img_rgb = cv2.cvtColor(r_img, cv2.COLOR_BGR2RGB)
|
| 78 |
+
st.image(img_rgb, caption="Rotation Applied", use_container_width=True)
|
| 79 |
+
|
| 80 |
|
| 81 |
if uploaded_file is not None:
|
| 82 |
# Converting the image into array
|
|
|
|
| 87 |
# img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 88 |
transformation = []
|
| 89 |
if trans:
|
| 90 |
+
translation(img)
|
| 91 |
transformation.append("Translation")
|
| 92 |
if rot:
|
| 93 |
transformation.append("Rotation")
|