Showing posts with label OpenCV. Show all posts
Showing posts with label OpenCV. Show all posts

Wednesday, 28 January 2015

Game Player - Step 2 - Calculate the Best Move

This is an unfinished article posted to save it sitting in Draft limbo forever.

Now that we have our game state we can move on to working out what move we should make. We could, if we wanted, just click randomly on the game board and hope for results but that wouldn't really be in keeping with the project's aim, we want the system to actually play the game.

Deciding what the best move is depends on what we feel best means. Imagine a shoot'em up game where we are flying through space blasting aliens. We might decide it is best to go for the power up first and then dispatch the enemies or we might decide it is better to clear the screen of enemies and think of power-ups as a secondary objective. If we really wanted we could create a machine leaning algorithm that decides itself what is best based on experience, but that is for another day! For now we will stick to deciding ourselves what our goal is and that will help us decide what the best way to achieve it is.

Tuesday, 9 October 2012

Game Player - Step 1.5 - Tidying Up The Code

We have done a lot of work over the last few posts and looked at some interesting features of OpenCV.

As it stands there is a lot of this stuff, although handy for debugging, we don't need in our final system. Things like the calls to printf and cout slow the system down unnecessarily so we can remove them. We can also take this opportunity to separate the majority of the code into its own method that completes the task of getting the game state. This will make the flow of the call to C easier to see and allow us to easily replace ways of completing a task (such as finding the colour of a game piece in an image) easier which is handy if we want to try out new algorithms.

Wednesday, 26 September 2012

Game Player - Step 1 - Finding the Game Board

I seem to be spending a great amount of time writing blog posts and not a huge amount of time actually progressing with the program. I think this is because a lot of my time so far has been spent capturing screen shots for the setting up portion of the system so now that that is over with things should proceed a bit more briskly.

So we've got our image data in C and we also have the ability to generate a window, let's combine the two so we can see our image from C and that way we can be certain that we do in fact have our image data and not just a jumble of non-sense.

Thursday, 9 August 2012

Problems Setting up 64 bit OpenCV

If you've been following the Game Player project I've been blogging about you'll know I has some trouble getting the 64 bit libraries of OpenCV to link with my project and had to stick with the 32 bit ones. Here I'll go into more details about the problem and hopefully find a solution.

First a little bit of background information on my system:
  • Windows 7 Home Premium 64 bit
  • OpenCV 2.4.2 pre-compiled binaries
  • Netbeans 7.0.1
  • Java 1.6 (not sure of bitness)
  • MinGW-32 C Compiler with gcc version 4.5.2

Wednesday, 8 August 2012

Game Player - Step 1 - Setting Up and Using OpenCV

This is the part I hate the most because it can be fraught with errors and you can end up spending masses of time on what is essentially just setting up the environment. I don't mind spending ages on a problem when it is a problem in development or trying to work out how to solve a tricky algorithm issue but spending ages on just setting something up drives me mad. Hopefully it will go smoothly this time...

Friday, 6 July 2012

Fixes in OpenCV and RTSP

We've finally got it going!

I'll get onto what was wrong in a second but first I want to share this line with you:

    CvCapture *camera = cvCreateFileCapture("rtsp://admin:admin@192.168.1.128/ch1-s1?tcp"); 

As you can see it is the same as my camera connection url in the previous post except I've added ?tcp to the end. I've found that this forces the rtsp connection to run using the tcp protocol instead of the udp protocol which is useful if you can't afford to have any packet loss. This gives us a decent picture but still performed very poorly, freezing often and dropping the frame rate down to something terrible.

Monday, 18 June 2012

Issues with OpenCV and RTSP

For months now I've been fighting with OpenCV to try and get a decent image coming through my internet camera and it's really beginning to drive me mad. I've got a reasonable little program to test the connection which looks like this:
/* 
 * File:   main.cpp
 * Author: Ryan
 *
 * Created on October 27, 2011, 2:23 PM
 */
#include <cstdlib>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/video/tracking.hpp"
#include <stdio.h> 

using namespace std;
using namespace cv;

int main() {
// CvCapture *camera = cvCreateFileCapture("/home/ryan/NetBeansProjects/OpenRTSP/video-H264-1");
// CvCapture *camera = cvCreateFileCapture("stream_fifo");    
// CvCapture *camera = cvCreateFileCapture("Wildlife.wmv");
   CvCapture *camera = cvCreateFileCapture("rtsp://admin:admin@192.168.1.128/ch1-s1"); //purple cam /?tcp
// CvCapture *camera=cvCreateFileCapture("http://192.168.1.5/image.jpg"); //black cam
// CvCapture *camera = cvCreateCameraCapture(0); //built in cam
// cvWaitKey(10000); 
    if (camera == NULL) {
        printf("camera is null, aborting...");
        return -1;
    }
    printf("camera is not null\n");
    fflush(stdout);
    cvNamedWindow("img");
    int i = 0;
    while (cvWaitKey(100) != 27) {
 // CvCapture *camera=cvCreateFileCapture("http://192.168.1.5/image.jpg");
        IplImage *img = cvQueryFrame(camera);
            if (img == NULL) break;
        cvShowImage("img", img);
// cvReleaseCapture(&camera); 
// printf("Image: %i\n", ++i);
        }
    cvReleaseCapture(&camera);
    return 0;
}