CV Cropped Frame

GCV scripting for Gtuner IV and Titan Two. Configuration, examples, questions.

CV Cropped Frame

Postby DeadbotE » Wed May 05, 2021 7:48 pm

Would like to crop a frame and pop out the cropped frame that Im working with in another window while I'm playing. I'm not having much luck with cv.newWindow or cv.imshow without the tuner crashing. I'm just getting back to the tuner and would like to update the Modern Warfare Pro Pack with CV but I cant remember how to process the frame.
User avatar
DeadbotE
Private
Private
 
Posts: 1
Joined: Fri Oct 11, 2019 11:56 pm

Re: CV Cropped Frame

Postby Scachi » Thu May 06, 2021 9:14 am

Using threading module and cv2 namedWindow with imgShow seems to work for me without blocking gtuner:
Code: Select all
 
import os
import cv2
import time
import threading
 
imgCropped = None  # the cropped frame content to show
imgShow = 1 # set somewhere in your code to 0 to stop thread
 
class GCVWorker:
    def __init__(self, width, height):
        os.chdir(os.path.dirname(__file__))
 
        self.img = IMGTHREAD(1)
        self.img.start()
 
    def __del__(self):
        del self.img
 
    def process(self, frame):
        global imgShow, imgCropped
        if imgShow == 1# flag to do the crop once
            imgCropped = frame[0:100, 0:200]
            imgShow = 2  # flag to do the crop once
        return frame, None
 
class IMGTHREAD (threading.Thread):
    def __init__(self, threadID):
        threading.Thread.__init__(self, daemon = True)
        self.threadID = threadID
 
    def run(self):
        imgCropShow()
 
def imgCropShow():
    global imgShow, imgCropped
 
    while imgShow:
        while imgCropped is not None:
            cv2.namedWindow('cropped')
            cv2.imshow('cropped', imgCropped)  # show cropped frame
            cv2.waitKey(1)  # to respond to inputs
            if cv2.getWindowProperty('cropped', cv2.WND_PROP_VISIBLE) < 1# window got closed
                imgCropped = None
        time.sleep(1)  # to not use much cpu time
 
 
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to Gtuner Computer Vision

Who is online

Users browsing this forum: No registered users and 15 guests