seeing machines

Week 1-2:

Conway’s Game of Life is a cellular automata simulation where a 2D grid of cells evolve between alive and dead states.

  • The Game of Life is a zero-player game, where you just set the initial state and the rules, and watch the evolution happen.
  • A cell’s state in the next frame depends on the state of its immediate neighbors in the current frame. It is set by counting the number of live or dead neighbors and applying the corresponding rule.
  • Depending on this initial state and rules, interesting patterns can emerge where cells can appear to oscillate or travel across the board.

#include “ofApp.h”

//————————————————————–
void ofApp::setup(){
floorImage.load(“photo.jpg”);
ofSetWindowShape(floorImage.getWidth(), floorImage.getHeight());
}

//————————————————————–
void ofApp::update() {

}

//————————————————————–
void ofApp::draw(){
floorImage.draw(0, 0);
ofPixels floorPix = floorImage.getPixels();

for (int y = 0; y < floorImage.getHeight(); y++)
{//画幅高
for (int x = 0; x < floorImage.getWidth(); x++)
{//画幅宽
int statusCount = 0;
ofColor col = floorImage.getColor(x, y);
if (col == ofColor(0)) {//死亡
for (int i = y – 1; i < y + 2; i++) {
for (int j = x – 1; j < x + 2; j++) {//死亡目标坐标的周围
ofColor colAround = floorImage.getColor(j, i);
if (colAround != ofColor(0)) {
statusCount++;
}
}
}
if (statusCount == 3) {
floorPix.setColor(x, y, ofColor(255));
}
}
else {
for (int k = y – 1; k < y + 2; k++) {
for (int l = x – 1; l < x + 2; l++) {
ofColor colAround = floorImage.getColor(l, k);
if (colAround == ofColor(0)) {//存活目标坐标的周围
statusCount++;
}
}
}
}

if (statusCount >= 2 && statusCount<=3) {
floorPix.setColor(x, y, ofColor(0));
}
}
}
floorImage.setFromPixels(floorPix);
}

I solved the problem by using two loops to identify each pixel and set the rules around the impact of the square, and it worked as I expected.

week 3 Opencv

I firstly try to use my laptop camera as the default and make the background subtraction, I also combine the GuiPanel so that it’s more user friendly.

By using this, users can change the windowScale by their want and do not effect anything

// Save the color of the pixel under the mouse.

int x = (ofGetMouseX() / (float)ofGetWidth()) * processImg.getWidth();
//int y = (ofGetMouseY() / (float)ofGetHeight()) * processImg.getHeight();

int y = ofMap(ofGetMouseY(), 0, ofGetHeight(), 0, processImg.getHeight(), true);

colorUnderMouse = processImg.getColor(x, y);

week 4-5 depth sensor