in Education by
Below, I have a python script. The part that is not working is the function cv2.moveWindow("TrackBars", WIDTH, 0). I haven't a clue why it isn't working because I can use the moveWindow function on my other "my ***" window. I initialized the "TrackBars" window and resized it before I try to use the moveWindow function. The point of the script is to make a camera window and have another window with inputs that change the position of a circle that is drawn on the camera window. import cv2 print(cv2.__version__) ***=cv2.VideoCapture(0) WIDTH=640 HEIGHT=480 ***.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH) ***.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT) ***.set(cv2.CAP_PROP_FPS, 30) ***.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG")) xPos = WIDTH//2 yPos = HEIGHT//2 radius = 25 def setX(x): global xPos xPos = x def setY(y): global yPos yPos = y def setRadius(r): global radius radius = r cv2.namedWindow("TrackBars") cv2.resizeWindow("TrackBars", 250, 100) cv2.moveWindow("TrackBars", WIDTH, 0) cv2.createTrackbar("xPos", "TrackBars", WIDTH//2, WIDTH, setX) cv2.createTrackbar("yPos", "TrackBars", HEIGHT//2, HEIGHT, setY) cv2.createTrackbar("radius", "TrackBars", 25, HEIGHT//2, setRadius) while True: ignore, frame = ***.read() cv2.circle(frame, (xPos, yPos), radius, (0, 255, 0), 2) cv2.imshow('my WEBcam', frame) cv2.moveWindow('my WEBcam',0,0) if cv2.waitKey(1) == ord('q'): break ***.release() JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
According to your code, you can move "TrackBars" window, but can't move "my WEBcam" window, because you used fixed coordinate values in the while loop: while True: ... cv2.moveWindow('my WEBcam',0,0) ... If you want to move the window, just comment out the line: while True: ... # cv2.moveWindow('my WEBcam',0,0) ... In addition, to make the "TrackBars" window on top of the "my WEBcam" window, you need to add one more line: cv2.namedWindow("my WEBcam") cv2.namedWindow("TrackBars") I've modified the code to test the "TrackBars" window: import cv2 print(cv2.__version__) ***=cv2.VideoCapture(0) WIDTH=640 HEIGHT=480 ***.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH) ***.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT) ***.set(cv2.CAP_PROP_FPS, 30) ***.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG")) xPos = WIDTH//2 yPos = HEIGHT//2 radius = 25 windowX = 0 def setX(x): global xPos xPos = x def setY(y): global yPos yPos = y def setRadius(r): global radius radius = r def setWindowX(x): global windowX windowX = x cv2.namedWindow("my WEBcam") cv2.namedWindow("TrackBars") cv2.resizeWindow("TrackBars", 250, 200) cv2.moveWindow("TrackBars", windowX, 400) cv2.createTrackbar("xPos", "TrackBars", WIDTH//2, WIDTH, setX) cv2.createTrackbar("yPos", "TrackBars", HEIGHT//2, HEIGHT, setY) cv2.createTrackbar("radius", "TrackBars", 25, HEIGHT//2, setRadius) # Test moveWindow cv2.createTrackbar("moveWindow", "TrackBars", 25, HEIGHT//2, setWindowX) while True: ignore, frame = ***.read() cv2.circle(frame, (xPos, yPos), radius, (0, 255, 0), 2) cv2.imshow('my WEBcam', frame) cv2.moveWindow('my WEBcam',0,0) cv2.moveWindow("TrackBars", windowX, 400) if cv2.waitKey(1) == ord('q'): break ***.release() macOS Windows

Related questions

0 votes
    Below, I have a python script. The part that is not working is the function cv2.moveWindow("TrackBars" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    Hello I am quite new to pygame and I am trying to make an intro for a game where the user hovers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I am getting errors for the code when running it on a 'tips' dataset but I can run it on a tulips dataset ... . Am I missing something? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    import re text = 'The quick. black n brown? fox jumps*over the lazy dog.' print(re.split('; | ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    def main(): for i in xrange(10**8): pass main() This piece of code in Python runs in (Note: The timing is ... sys 0m0.012s Why is this? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I think I am misunderstanding something. I think that printed results of this code snippet must be equal, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I think I am misunderstanding something. I think that printed results of this code snippet must be equal, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    I'm trying to figure out Python lambdas. Is lambda one of those "interesting" language items that in ... maintenance coder nightmare. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I've seen some code samples and tutorials that use def main(): # my code here if __name__ == "__main__": ... any rhyme to the main? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
...