LakshmiHarika commited on
Commit
fbdd0ef
·
verified ·
1 Parent(s): 1c4c27c

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +66 -0
pages/Data Collection.py CHANGED
@@ -1376,6 +1376,72 @@ elif st.session_state.current_page == "image_transformations":
1376
  cv2.destroyAllWindows()
1377
  """, language="python")
1378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1379
 
1380
 
1381
 
 
1376
  cv2.destroyAllWindows()
1377
  """, language="python")
1378
 
1379
+ # Explanation for Rotation
1380
+ st.markdown("""
1381
+ <h3 style="color: #9400d3;">Rotation</h3>
1382
+ """, unsafe_allow_html=True)
1383
+
1384
+ st.write("""
1385
+ **Rotation** involves rotating an image around a specified center point by a given angle. It changes the orientation of the image while preserving its content.
1386
+
1387
+ The rotation is performed using a rotation matrix:
1388
+
1389
+ [[cos(θ), -sin(θ), tx], [sin(θ), cos(θ), ty]]
1390
+
1391
+ Here:
1392
+ - **θ (theta)**: Specifies the rotation angle in degrees.
1393
+ - **tx, ty**: Specifies the adjustments to reposition the rotated image.
1394
+ - **Scale**: A factor that can resize the image during rotation.
1395
+ """)
1396
+
1397
+ # Code Example
1398
+ st.code("""
1399
+ # Define the rotation matrix
1400
+ r_m = cv2.getRotationMatrix2D((1347, 900), 50, 1) # Center at (1347, 900), Rotate by 50 degrees, Scale = 1
1401
+
1402
+ # Apply rotation
1403
+ r_img = cv2.warpAffine(img, r_m, (580, 500), borderMode=cv2.BORDER_DEFAULT)
1404
+
1405
+ # Display the images
1406
+ cv2.imshow("Original Image", img)
1407
+ cv2.imshow("Rotated Image", r_img)
1408
+
1409
+ cv2.waitKey(0)
1410
+ cv2.destroyAllWindows()
1411
+ """, language="python")
1412
+
1413
+ # Explanation for Direct Rotation
1414
+ st.markdown("""
1415
+ <h3 style="color: #9400d3;">Direct Rotation Using cv2.rotate</h3>
1416
+ """, unsafe_allow_html=True)
1417
+
1418
+ st.write("""
1419
+ OpenCV provides a direct method for rotating images with predefined angles: `cv2.rotate`.
1420
+ This method simplifies rotation operations for 90°, 180°, and 270° (clockwise or counterclockwise) without requiring a custom rotation matrix.
1421
+
1422
+ ### Available Rotation Modes:
1423
+ - **`cv2.ROTATE_180`**: Rotates the image by 180°.
1424
+ - **`cv2.ROTATE_90_CLOCKWISE`**: Rotates the image by 90° clockwise.
1425
+ - **`cv2.ROTATE_90_COUNTERCLOCKWISE`**: Rotates the image by 90° counterclockwise.
1426
+ """)
1427
+
1428
+ # Code Example
1429
+ st.code("""
1430
+ # Rotate the image using predefined rotation modes
1431
+ img1 = cv2.rotate(img, cv2.ROTATE_180) # Rotate 180 degrees
1432
+ img2 = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE) # Rotate 90 degrees clockwise
1433
+ img3 = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE) # Rotate 90 degrees counterclockwise
1434
+
1435
+ # Display the images
1436
+ cv2.imshow("Original Image", img)
1437
+ cv2.imshow("Rotated 180°", img1)
1438
+ cv2.imshow("Rotated 90° Clockwise", img2)
1439
+ cv2.imshow("Rotated 90° Counterclockwise", img3)
1440
+
1441
+ cv2.waitKey(0)
1442
+ cv2.destroyAllWindows()
1443
+ """, language="python")
1444
+
1445
 
1446
 
1447