Need help with gcv script

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

Need help with gcv script

Postby rasalghul » Sat Oct 02, 2021 3:45 pm

Hello, I have a problem with my gcv and gpc script. Why am I not getting the "yuna_attack" combo? Where do I have a mistake in reasoning? Thanks for the help.

Code: Select all
#pragma METAINFO("battle", 1, 04, "rasalghul")
 
#include <keyboard.gph>
#include <mouse.gph>
 
// KEYS
//
// ----------------------------------------------------------------------------------------------------------------
 
#define AB01 KEY_C
#define UP KEY_UPARROW
#define DOWN KEY_DOWNARROW 
#define LEFT KEY_LEFTARROW
#define RIGHT KEY_RIGHTARROW
 
// VARIABLES
//
// ----------------------------------------------------------------------------------------------------------------
 
bool tidus = FALSE;
bool yuna = FALSE;
bool battleend = FALSE;
int  led_change_flag = 0;
 
// INIT
//
// ----------------------------------------------------------------------------------------------------------------
 
init {
 
    // AUTO OUTPUT PROTOCOL
 
    port_connect(PORT_USB_C, PROTOCOL_HID);
 
    keymapping();
       mousemapping();
 
}
 
main {
 
    // HID PASSTHROUGH
    //
    // ----------------------------------------------------------------------------------------------------------------
 
    key_passthru();
    mouse_passthru();
 
    if(gcv_ready()) {
        tidus = gcv_read(0);
        yuna = gcv_read(1);
        battleend = gcv_read(2);
    }
 
    if(tidus)
        combo_run(tidus_attack);
 
    if(yuna)
        combo_run(yuna_attack);
 
    if(battleend)
        combo_run(be);
 
}
 
combo tidus_attack
 
{
 
    wait(irand(500)); //start delay
    key_set(AB01, TRUE);
    wait(irand(60));
    key_set(AB01, FALSE);
    wait(irand(60));
    wait(irand(60));
    wait(irand(500));
    key_set(AB01, TRUE);
    wait(irand(60));
    key_set(AB01, FALSE);
    wait(irand(60));
    wait(irand(60));   
 
}
 
combo yuna_attack
 
{
 
    wait(irand(500)); //start delay
    key_set(DOWN, TRUE);
    key_set(DOWN, FALSE);
    wait(irand(200));
 
}
 
combo be
 
{
 
    wait(irand(500)); //start delay
    key_set(AB01, TRUE);
    wait(irand(60));
    key_set(AB01, FALSE);
    wait(irand(60));
    wait(irand(500));
    key_set(AB01, TRUE);
    wait(irand(60));
    key_set(AB01, FALSE);
    wait(irand(60));
    wait(irand(500));
    key_set(AB01, TRUE);
    wait(irand(60));
    key_set(AB01, FALSE);
    wait(irand(60));
 
}
 
// FUNCTIONS
//
// ----------------------------------------------------------------------------------------------------------------
 
// Diese Funktion nimmt einen Wert an und gibt eine leicht zufällige Version der ursprünglichen Zahl zurück (innerhalb eines 10%-Fensters).
int irand(int scramble) {
    fix32 fraction = (fix32) scramble * 0.10;
    int vmin = scramble - (int) fraction;
    int vmax = scramble + (int) fraction;
    return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);
}
 
// LED Funktion
void ColorLED(char Color) {
    fix32 Color1, Color2, Color3, Color4;
 
    if(Color == 'B'){Color1 = 100.00;    Color2 = 0.00;    Color3 = 0.00;    Color4 = 0.00;} // Blau
    if(Color == 'R'){Color1 = 0.00;    Color2 = 100.00;    Color3 = 0.00;    Color4 = 0.00;} // Rot
    if(Color == 'G'){Color1 = 0.00;    Color2 = 0.00;    Color3 = 100.00;    Color4 = 0.00;} // Grün
    if(Color == 'P'){Color1 = 0.00;    Color2 = 0.00;    Color3 = 0.00;    Color4 = 100.0;} // Lila
    if(Color == 'Y'){Color1 = 0.00;    Color2 = 100.00;    Color3 = 100.00;    Color4 = 0.0;} // Gelb
 
    led_set(LED_1, Color1, 0);
    led_set(LED_2, Color2, 0);
    led_set(LED_3, Color3, 0);
    led_set(LED_4, Color4, 0);
 
    return;
}


Code: Select all
import os
import cv2
 
 
class GCVWorker:
    def __init__(self, width, height):
        os.chdir(os.path.dirname(__file__))
        self.gcvdata = bytearray([0xFF, 0xFF, 0xFF])
        #self.gcvdata = bytearray()
        #self.gcvdata.extend(int(value).to_bytes(2, byteorder='big', signed=True))
        self.char = cv2.imread('img/titus.jpg') # tidus
        self.battleend = cv2.imread('img/battleend.jpg')
        self.foundBattleEnd = True
        self.found01 = True
        self.found02 = True
 
    def __del__(self):
        del self.gcvdata
        del self.char # tidus
        del self.battleend
 
    def process(self, frame):
        self.gcvdata[0] = False # tidus
        self.gcvdata[1] = False # yuna
        self.gcvdata[2] = False
        picturechar = frame[186:219, 1326:1381]
        picturebattleend = frame[764:873, 1326:1381]
 
        similarchar = cv2.norm(self.char, picturechar) # tidus
        similarbattleend = cv2.norm(self.battleend, picturebattleend)
 
        if similarchar == 424.3147416717925 and self.found01: # tidus
            print('Found: Tidus')
            self.found01 = False
            self.gcvdata[0] = True
 
        elif similarchar == 5998.489643235203 and self.found02: # yuna
            print('Found: Yuna')
            self.found02 = False
            self.gcvdata[1] = True
 
        elif similarchar == 424.3147416717925: # tidus
            pass
 
        elif similarchar == 5998.489643235203: # yuna
            pass
 
        else:
            self.found01 = True
            self.found02 = True
            #print(similarchar)
 
        if similarbattleend == 217.158927976724 and self.foundBattleEnd:
            print('Found: Battle End')
            self.foundBattleEnd = False
            self.gcvdata[2] = True
 
        elif similarbattleend == 217.158927976724: # battle end
            pass
 
        else:
            self.foundBattleEnd = True
            #print(similarbattleend)
 
        return frame, self.gcvdata
 
User avatar
rasalghul
Corporal
Corporal
 
Posts: 4
Joined: Sat Oct 02, 2021 3:40 pm

Return to Gtuner Computer Vision

Who is online

Users browsing this forum: No registered users and 28 guests