Code Monkey home page Code Monkey logo

opencv_tutorials's People

Contributors

learncodebygaming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv_tutorials's Issues

vision.py (ep 5)

File "main.py", line 31, in
points = vision_limestone.find(screenshot, 0.5, 'rectangles')
File "C:\Users\x\Documents\x\lx\vision.py", line 29, in find
result = cv.matchTemplate(haystack_img, self.needle_img, self.method)
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-52oirelq\opencv\modules\imgproc\src\templmatch.cpp:1163: error: (-215:Assertion failed) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function 'cv::matchTemplate'

Not sure what's causing this. My own version of the code causes it and then I tried directly copying the file structure and this still happens

res = cv2.matchTemplate

hey there, I'm having difficulty figuring out how to get my template to match the game recording for my code. This is the test code that I'm trying to run, and it just doesn't seem to work. I do realize I haven't run the exact code that you put on your videos, but that is because I can't seem to get it to window/video capture for the game I'm playing, (which is a little frustrating).
Nevertheless, it works for still image and it works fine videocapturing when I don't try to matchTemplate but the two don't seem to want to merge.

import numpy as np
from PIL import ImageGrab
import cv2
import time
import threading

def screen_record(): 
     last_time = time.time()
     while(True):
         # 800x600 windowed mode for GTA 5, at the top left position of your main screen.
         # 40 px accounts for title bar. 
         printscreen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
         print('loop took {} seconds'.format(time.time()-last_time))
         last_time = time.time()
         img_gray = cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2GRAY))
         if cv2.waitKey(25) & 0xFF == ord('q'):
             cv2.destroyAllWindows()
             break

    eyes_hungry = cv2.imshow('hungry2.jpg',0)
    last_time = time.time()
    res = cv2.matchTemplate(img_gray, eyes_hungry, cv2.TM_CCOEFF_NORMED)       
    threshhold = 0.8
    loc = np.where(res >= threshhold)
    for pt in zip(*loc[::-1]):
        w, h = template.shape[::-1]
        cv2.rectangle(img_gray, pt, (pt[0]+w, pt[1]+h), (0,255,255), 1)


screen_record()

this is the error or a variation on the same error I get when I try running it:

  F:\Desktop\Ne\neat-python>grabscreen.py                                                    
loop took 0.0657804012298584 seconds                                                       
Traceback (most recent call last):                                                         
  File "F:\Desktop\Ne\neat-python\grabscreen.py", line 29, in <module>                     
    screen_record()                                                                        
  File "F:\Desktop\Ne\neat-python\grabscreen.py", line 22, in screen_record                
    res = cv2.matchTemplate(img_gray, eyes_hungry, cv2.TM_CCOEFF_NORMED)                   
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\imgproc\src\templmatch.cpp:588: error: (-215:Assertion failed) corr.rows <= img.rows + templ.rows - 1 && corr.cols <= img.cols + templ.cols - 1 in function 'cv::crossCorr'

if you or anyone might be able to help, I'd really appreciate it, I've been banging my head on the wall for a few days now.

Thank you for reading.

please help me

wincap = WindowCapture('Blacksmith')

vision_limestone = Vision('greenday.jpg') ------------> if see = and click
vision_limestone2 = Vision('greenperfect.jpg.jpg') ---------> when click 1 this appear and track and click

loop_time = time()
while(True):
screenshot = wincap.get_screenshot()
points = vision_limestone.find(screenshot, 0.7, 'rectangles') ------------> same up
points2 = vision_limestone5.find(screenshot, 0.7, 'rectangles') ------------>

print('FPS {}'.format(1 / (time() - loop_time)))
loop_time = time()

I'm beginner. just now it see track Ok. I cant to code for click.
please help me.
thank you very much.

Windows Apps capturing a black screen

Using a test game (Big Farm) installed as windows application from the Microsoft Store, I only capture a black screen.
I know in a browser like google it is due to hardware acceleration, but this is a windows application built in a framework.
Has anyone figured out how to do this without a fullscreen capture?

TypeError: argument for rectangle() given by name ('color') and position (3)

Hello, I got started yesterday with this great tutorial, but I'm stuck at step 5.

When I run my code I get:

cv.rectangle(haystack_img, top_left, bottom_right, color=(0,255,0), thickness=2, lineType=cv.LINE_4)
TypeError: argument for rectangle() given by name ('color') and position (3)

I do not know why.

MatchTemplate and Threading

Did anyone figured out how to only use OpenCv - Template Matching instead of classifier
I'm trying to multi object detect with OpenCv
and use threads, But I can't figured it out, but nothing, error after error
Already 5 days I'm following Ben python series, and 2days i'm stuck on one thing is implementing threading for multiple template matching

getdc()

win32gui.GetDC() function retrieves a handle to a display device context for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the device context.

This returns an area without toolbar etc. Should simplify the code some.

Im also working on iterating through a list of windows with the same class or name and checking their pid against the pid of a subprocess i started. This will let me find which game window of the same title to manipulate

I love these videos im learning a lot!

Cascade classifier can`t be trained

Hello, have problem "Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters."

No output after running command.

I run the command.
D:/OpenCV/build/x64/vc15/bin/opencv_traincascade.exe -data 008_cascade_classifier/cascade -vec pos.vec -bg 008_cascade_classifier/neg.txt -w 300 -h 300 -numPos 200 -numNeg 100 -numStages 10
But I get no output, no error, no success.
Here's how it looks in full.
PS C:\Users\VM\Documents\GitHub\opencv_tutorials> D:/OpenCV/build/x64/vc15/bin/opencv_traincascade.exe -data 008_cascade_classifier/cascade -vec pos.vec -bg 008_cascade_classifier/neg.txt -w 300 -h 300 -numPos 200 -numNeg 100 -numStages 10
PS C:\Users\VM\Documents\GitHub\opencv_tutorials>

win32ui DLLs Error

I'm working in Jupiter notebooks. When I tried to import win32ui, I received a DLLs Error. Can someone tell me how to fix this issue?

getting black screen only

so i used the code from vid #4 and when i run it with Albion Online Client it shows only a black screen . when i use other screens like paints it works perfectly . any got that issue ?

Thread implementation

Hi, first of all thanks for the series, it is great and really clear.
One question regarding how threads work.
When, for example, a Detector instance calls the update(self, screenshot) method:

class Detection:
    def __init__(self, model_file_path):
        # create a thread lock object
        self.lock = Lock()
    (......)
    def update(self, screenshot):
           self.lock.acquire()
           self.screenshot = screenshot
           self.lock.release()

Shouldn' t the lock acquired by the method be the one of the WindowCapture instance? I don't understand how threads are talking to each other if the locks they acquired are the ones enclosed in the objects each of them are supposed to manage.

Thanks in advance!

Getting vscode window

I use the code from vid #5 . But i encounter problem that's when capture albion online client window instead i get the vscode window.Is there something that's i did wrong ? But when i capture any other windows i can get them.It's only wrong with albion online client window

Cropped image in opencv_annotation

I am following the tutorial for cascade classifier. When I run the command to create the pos.txt and draw the rectangles around images, the window opens but it shows only a part of the picture. How can I make it show the full picture?

Screen shot is cached

get an updated image of the game

screenshot = wincap.get_screenshot()

screenshot is cached, every time i attempt to my game is showing first screenshot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.