Skip to content

Comments

Task 4#6

Open
gitfrandu4 wants to merge 1 commit intomainfrom
task-4
Open

Task 4#6
gitfrandu4 wants to merge 1 commit intomainfrom
task-4

Conversation

@gitfrandu4
Copy link
Owner

Script:

vid = cv2.VideoCapture(0)

while True:
    # frame to frame
    ret, frame = vid.read()

    if not ret:
        # If we've reached the end of the video, reset to the beginning
        vid.set(cv2.CAP_PROP_POS_FRAMES, 0)
        continue

    # get the channels. OpenCV reads the image in BGR format
    b = frame[:,:,0] # blue channel
    g = frame[:,:,1] # green channel
    r = frame[:,:,2] # red channel
    
    b_increased = b + 100
    g_increased = g + 100
    r_increased = r + 100
    
    # altered frame with increased red channel
    altered_frame_b = frame.copy()
    altered_frame_g = frame.copy()
    altered_frame_r = frame.copy()

    altered_frame_b[:,:,0] = b_increased
    altered_frame_g[:,:,1] = g_increased
    altered_frame_r[:,:,2] = r_increased

    sepia_filter = np.array([[0.272, 0.534, 0.131],
                             [0.349, 0.686, 0.168],
                             [0.393, 0.769, 0.189]])

    # apply the sepia filter to the image
    sepia_frame = cv2.transform(frame, sepia_filter)

    # apply the sepia filter to the image
    sepia_frame = cv2.transform(frame, sepia_filter)

    # concatenate the altered frames and the sepia frame in 4x4 
    # Create a 4x4 collage
    top_row = np.hstack((altered_frame_b, altered_frame_g))
    bottom_row = np.hstack((altered_frame_r, sepia_frame))
    collage = np.vstack((top_row, bottom_row))

    # show the result image
    cv2.imshow('Cam', collage)

    # stop the video when the ESC key is pressed
    if cv2.waitKey(20) == 27:
        plt.imshow(collage)
        plt.axis('off')
        plt.show()
        break

# release the video capture object
vid.release()
# destroy the windows
cv2.destroyAllWindows()

Resultado:

image

@gitfrandu4 gitfrandu4 changed the title add task 4 Task 4 Sep 16, 2024
@gitfrandu4 gitfrandu4 requested a review from DerKom September 16, 2024 17:48
@gitfrandu4 gitfrandu4 self-assigned this Sep 16, 2024
@gitfrandu4 gitfrandu4 added the enhancement New feature or request label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant