vertopal.com_Copy of CVPR1 (1)
vertopal.com_Copy of CVPR1 (1)
image = cv2.imread('MESSI.jpg')
if image is None:
print("Error: Could not read the image.")
else:
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(image_rgb)
plt.axis('off')
plt.show()
cv2.imwrite('output_image.jpg', image)
print("Image written to 'output_image.jpg'")
input_image_path = 'MESSI.jpg'
image = cv2.imread(input_image_path)
if image is None:
print("Error: Could not read the image.")
else:
output_image_path = 'output_image_1.png'
cv2.imwrite(output_image_path, image)
print(f"Image converted and saved as '{output_image_path}'")
input_image_path = 'MESSI.jpg'
image = cv2.imread(input_image_path)
if image is None:
print("Error: Could not read the image.")
else:
original_height, original_width = image.shape[:2]
print(f"Original Dimensions: {original_width}x{original_height}")
new_width = 300
new_height = 200
new_dimensions = (new_width, new_height)
#Can put these dimensions as we please
resized_image = cv2.resize(image, new_dimensions) # For resizing ,
the rest is for saving the img
output_image_path = 'resized_image.jpg'
cv2.imwrite(output_image_path, resized_image)
print(f"Resized image saved as '{output_image_path}'")
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
resized_image_rgb = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(image_rgb)
plt.title('Original Image')
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(resized_image_rgb)
plt.title('Resized Image')
plt.axis('off')
plt.show()
if image is None:
print("Error: Could not read the image.")
else:
grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # For
making image grayscale rest is for saving the image
output_image_path = 'grayscale_image.jpg'
cv2.imwrite(output_image_path, grayscale_image)
print(f"Grayscale image saved as '{output_image_path}'")
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(image_rgb)
plt.title('Original Image')
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(grayscale_image, cmap='gray')
plt.title('Grayscale Image')
plt.axis('off')
plt.show()
input_image_path = 'MESSI.jpg'
image = cv2.imread(input_image_path)
if image is None:
print("Error: Could not read the image.")
else:
scale_factor = 0.5
scaled_image = cv2.resize(image, None, fx=scale_factor,
fy=scale_factor) # For Scaling
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
angle = 45
scale = 1.0
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)
rotated_image = cv2.warpAffine(image, rotation_matrix, (w, h)) #
For Rotation
translation_matrix = np.float32([[1, 0, 50], [0, 1, 30]])
shifted_image = cv2.warpAffine(image, translation_matrix, (w, h))
# For Shifting , the rest of the code is only to save the images
plt.figure(figsize=(15, 10))
plt.subplot(2, 2, 1)
plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
plt.title('Original Image')
plt.axis('off')
plt.subplot(2, 2, 2)
plt.imshow(cv2.cvtColor(scaled_image, cv2.COLOR_BGR2RGB))
plt.title('Scaled Image (50%)')
plt.axis('off')
plt.subplot(2, 2, 3)
plt.imshow(cv2.cvtColor(rotated_image, cv2.COLOR_BGR2RGB))
plt.title('Rotated Image (45 degrees)')
plt.axis('off')
plt.subplot(2, 2, 4)
plt.imshow(cv2.cvtColor(shifted_image, cv2.COLOR_BGR2RGB))
plt.title('Shifted Image (50 right, 30 down)')
plt.axis('off')
plt.show()
cap = cv2.VideoCapture('FISH.mp4')
if (cap.isOpened()== False):
print("Error opening video file")
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Frame', frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
----------------------------------------------------------------------
-----
DisabledFunctionError Traceback (most recent call
last)
<ipython-input-22-8d30034d6e4e> in <cell line: 0>()
7 ret, frame = cap.read()
8 if ret == True:
----> 9 cv2.imshow('Frame', frame)
10 if cv2.waitKey(25) & 0xFF == ord('q'):
11 break
/usr/local/lib/python3.11/dist-packages/google/colab/_import_hooks/
_cv2.py in wrapped(*args, **kwargs)
46 def wrapped(*args, **kwargs):
47 if not os.environ.get(env_var, False):
---> 48 raise DisabledFunctionError(message, name or
func.__name__)
49 return func(*args, **kwargs)
50
main()