//-------------------------------------------------------------- void testApp::update(){ captureWidth = ofGetWidth(); captureHeight = ofGetHeight(); unsigned char * data = pixelsBelowWindow(ofGetWindowPositionX(), ofGetWindowPositionY(), captureWidth, captureHeight); // now, let's get the R and B data swapped, so that it's all OK: for (int i = 0; i < captureWidth * captureHeight; i++){ unsigned char r = data[i*4]; // mem A data[i*4] = data[i*4+1]; data[i*4+1] = data[i*4+2]; data[i*4+2] = data[i*4+3]; data[i*4+3] = r; } if (data!= NULL) { //tex.loadData(data, captureWidth, captureHeight, GL_RGBA); //tex.readToPixels(pixels); //image = pixels; image.setFromPixels(data, captureWidth, captureHeight, OF_IMAGE_COLOR_ALPHA, true); image.setImageType(OF_IMAGE_COLOR); image.update(); finder.findHaarObjects(image.getPixelsRef()); } //cout << imageBelowWindow()[0] << endl; }
//------------- void ofxScreenGrab::grabScreen(int x, int y) { unsigned char * data = pixelsBelowWindow(x, y, width, height); for (int i = 0; i < rx*rx*width*height; i++){ unsigned char r1 = data[i*4]; data[i*4] = data[i*4+1]; data[i*4+1] = data[i*4+2]; data[i*4+2] = data[i*4+3]; data[i*4+3] = r1; } if (data!= NULL) tex.loadData(data, rx*width, rx*height, GL_RGBA); }
//-------------------------------------------------------------- void testApp::update() { if (origin.y > 0) { unsigned char *data = pixelsBelowWindow(origin.x, origin.y, 400, 400); cv::Mat argb(400, 400, CV_8UC4, data); cv::Mat rgb(400, 400, CV_8UC3); int fromTo[] = {1,0, 2,1, 3,2}; mixChannels(&argb, 1, &rgb, 1, fromTo, 3); ofxCv::toOf(rgb, image); image.reloadTexture(); getStateFromImage(); findAnswer(); if (selected.size()) { mouseThread.move(origin.x + (selected[0] + (ofRandom(1) < 0.5 ? -1 : 1)) * 50 + 23, origin.y + selected[1] * 50 + 23); return; } if (wildcard.size()) { mouseThread.click(origin.x + wildcard[0] * 50 + 23, origin.y + wildcard[1] * 50 + 23); return; // int max_count = 0; // unsigned int max_id = 0; // for (map<unsigned int, int>::iterator it = count.begin(); it != count.end(); it++) { // if (it->second > max_count) { // max_count = it->second; // max_id = it->first; // } // } // if (max_count > 0) { // cout << "max_id: " << max_id << ", count: " << max_count << endl; // for (int i = 0; i < wildcard.size(); i += 2) { // int x = wildcard[i]; // int y = wildcard[i + 1]; // if (state[x][y].id == max_id) { // mouseThread.click(origin.x + x * 50 + 23, origin.y + y * 50 + 23); // return; // } // } // } } if (answers.size() > 0) { Answer ans = answers.at(ofRandom(MIN(answers.size(), 3))); mouseThread.drag(origin.x + ans.x1 * 50 + 23, origin.y + ans.y1 * 50 + 23, origin.x + ans.x2 * 50 + 23, origin.y + ans.y2 * 50 + 23); } } }
//-------------------------------------------------------------- void testApp::findOrigin() { int width = ofGetScreenWidth(); int height = ofGetScreenHeight(); unsigned char *data = pixelsBelowWindow(0, 0, width, height); ofImage banner; banner.loadImage("banner.png"); float start = ofGetElapsedTimef(); cv::Mat captured(height, width, CV_8UC4, data, 0); cv::Mat screen(height, width, CV_8UC3); int fromTo[] = {1,0, 2,1, 3,2}; mixChannels(&captured, 1, &screen, 1, fromTo, 3); cv::Mat temp_img = ofxCv::toCv(banner); cv::Mat result_img; cv::matchTemplate(screen, temp_img, result_img, CV_TM_CCOEFF_NORMED); cv::Point max_pt; double maxVal; cv::minMaxLoc(result_img, NULL, &maxVal, NULL, &max_pt); cout << "(" << max_pt.x << ", " << max_pt.y << "), score=" << maxVal << ", time=" << (ofGetElapsedTimef() - start) << endl; if (maxVal > 0.9) { origin.x = max_pt.x + 20; origin.y = max_pt.y + 115 + 63; #if 0 for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { cv::Mat name = screen(cv::Rect(origin.x + x * 50, origin.y + y * 50, 46, 46)).clone(); ofImage nameko; ofxCv::toOf(name, nameko); nameko.reloadTexture(); char filename[256]; sprintf(filename, "nameko/%06x.png", nameko.getColor(23, 2).getHex()); ofFile file(filename); if (!file.exists()) { nameko.saveImage(file); } } } #endif ofSetWindowPosition(origin.x - ofGetWindowWidth() - 25, origin.y - 1); } }
//-------------------------------------------------------------- void testApp::update(){ int w = 300; int h = 300; unsigned char * data = pixelsBelowWindow(ofGetWindowPositionX(),ofGetWindowPositionY(),w,h); // now, let's get the R and B data swapped, so that it's all OK: for (int i = 0; i < w*h; i++){ unsigned char r = data[i*4]; data[i*4] = data[i*4+2]; data[i*4+2] = r; } if (data!= NULL) tex.loadData(data, 300, 300, GL_RGBA); //cout << imageBelowWindow()[0] << endl; }