Python Forum
Display the bottom image of the line and cut the upper image using Opencv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display the bottom image of the line and cut the upper image using Opencv
#1
I am trying to crop the live video diagonally. With the help of cv.line, I have mentioned the dimensions and my goal is to display the video of the lower side of the line I have drawn and the upper video should be cropped, As a beginner, I was just able to draw a line using the following code:

import cv2

cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False

while rval:
    cv2.imshow("preview", frame)
    rval, frame = vc.read()
    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
        break
    else:
        cv2.line(img=frame, pt1=(700,5), pt2=(5, 450), color=(255, 0, 0), thickness=1, lineType=8, shift=0)

vc.release()
cv2.destroyWindow("preview")
Output:
[Image: QJcUL.jpg]

Suggestion on this will be very helpful

Attached Files

Thumbnail(s)
   
Reply
#2
The idea is: rotate, crop, rotate back:
#!/usr/bin/python3
import cv2
import imutils

cv2.namedWindow("preview").
vc = cv2.VideoCapture('test.mp4')

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()
else:
    rval = False

while rval:
    cv2.imshow("preview", frame)
    rval, frame = vc.read()
    if rval:
        frame = imutils.rotate_bound(frame, 45)

        h = frame.shape[0]
        w = frame.shape[1]
        frame = frame[h//2:h, 0:w]

        frame = imutils.rotate_bound(frame, -45)

    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
        break

vc.release()
cv2.destroyWindow("preview")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo image error pyc0de 2 250 Mar-23-2024, 06:20 PM
Last Post: pyc0de
  Using OpenCV and image path is invalid AudunNilsen 5 545 Mar-18-2024, 05:28 PM
Last Post: snippsat
  Count image's colors very fast flash77 18 1,543 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,865 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  error "cannot identify image file" part way through running hatflyer 0 666 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  Mirror Video Image in realtime makingwithheld 1 427 Oct-30-2023, 02:45 PM
Last Post: Larz60+
  howto get size of a ctk image? janeik 2 853 Oct-03-2023, 03:49 AM
Last Post: janeik
  Use of PIL.Image nafshar 12 2,100 Sep-07-2023, 11:02 PM
Last Post: nafshar
Question image manipulation (cropping and MetaData) SpongeB0B 4 1,153 Jul-03-2023, 06:35 PM
Last Post: SpongeB0B
  Save image from outlook email cubangt 1 690 Jun-07-2023, 06:52 PM
Last Post: cubangt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020