Skip to content

Commit

Permalink
Merge pull request #19 from ibmtjbot/refactor/jw-captureImage
Browse files Browse the repository at this point in the history
Improved camera operations
  • Loading branch information
victordibia authored Apr 20, 2017
2 parents d5e1835 + b33db9e commit c250902
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ objects =
]
```

### tj.recognizeObjectsInPhoto(filePath)

Returns a list of objects seen and their confidences in the given photo.

- `filePath` is the path to the photo to use.

Sample usage:

```
tj.recognizeObjectsInPhoto(filePath).then(function(objects)) {
...
});
```

The response is the same as `tj.see()`.

### tj.read()

Returns a list of text strings read by TJBot.
Expand All @@ -396,6 +412,22 @@ Sample response:
TBD
```

### tj.recognizeTextInPhoto(filePath)

Returns a list of text strings read by TJBot in the given photo.

- `filePath` is the path to the photo to use.

Sample usage:

```
tj.recognizeTextInPhoto(filePath).then(function(texts)) {
...
});
```

The response is the same as `tj.read()`.

### tj.takePhoto(targetPath)

Takes an argument of the path `targetPath` where the image file should be saved. If `targetPath` is null, image is stored in a temporary location. This method also returns the location `filePath` where image file was saved.
Expand Down
55 changes: 23 additions & 32 deletions lib/tjbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function TJBot(hardware, configuration, credentials) {
/**
* TJBot module version
*/
TJBot.prototype.version = 'v1.2.0';
TJBot.prototype.version = 'v1.2.1';

/**
* List of TJBot hardware and services.
Expand Down Expand Up @@ -198,8 +198,23 @@ TJBot.prototype._setupCamera = function() {
encoding: 'jpg',
outputDir: './',
verticalFlip: this.configuration.see.camera.verticalFlip,
horizontalFlip: this.configuration.see.camera.horizontalFlip
horizontalFlip: this.configuration.see.camera.horizontalFlip,
time: 1
});

// versions of node-raspistill < 0.0.11 don't have the `time` option, so
// force it in if we don't find it
if (!this._camera.options.hasOwnProperty('time')) {
winston.silly("node-raspistill camera option for `time` not found, swizzling it in");
var self = this._camera;
self.processOptionsOriginal = self.processOptions;
self.processOptions = function(newOptions) {
var options = self.processOptionsOriginal(newOptions);
options.push('-t');
options.push('1');
return options;
}
}
}

/**
Expand Down Expand Up @@ -775,8 +790,6 @@ TJBot.prototype.recognizeObjectsInPhoto = function(filePath) {
});
}



/**
* Take a picture and read the identified text.
*
Expand Down Expand Up @@ -823,7 +836,6 @@ TJBot.prototype.recognizeTextInPhoto = function(filePath) {
});
}


/**
* Capture an image and save it in the given path. If no path is provided, it saves this file to a temp location
*
Expand Down Expand Up @@ -851,9 +863,14 @@ TJBot.prototype.takePhoto = function(filePath) {
name = filePath.substring(filePath.lastIndexOf("/") + 1);
name = name.replace(".jpg", ""); // the node raspistill lib already adds encoding .jpg to file.

// set the configuration options, which may have changed since the camera was initialized
this._camera.setOptions({
outputDir: path,
fileName: name
fileName: name,
width: this.configuration.see.camera.width,
height: this.configuration.see.camera.height,
verticalFlip: this.configuration.see.camera.verticalFlip,
horizontalFlip: this.configuration.see.camera.horizontalFlip
});

return new Promise(function(resolve, reject) {
Expand All @@ -867,32 +884,6 @@ TJBot.prototype.takePhoto = function(filePath) {
})
}

/**
* Capture an image and save it in the given path.
*
* @param {String} filePath The path at which to save the image.
*
* Returns the photo data in a Buffer.
*/
TJBot.prototype._captureImage = function(filePath) {
this._assertCapability('see');

// capture 'this' context
var self = this;

winston.debug("capturing image at path: " + filePath + ".jpg");

var path = filePath.substring(0, filePath.lastIndexOf("/"));
var name = filePath.substring(filePath.lastIndexOf("/") + 1);

this._camera.setOptions({
outputDir: path,
fileName: name
});

return this._camera.takePhoto();
}

/** ------------------------------------------------------------------------ */
/** SHINE */
/** ------------------------------------------------------------------------ */
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tjbot",
"description": "Node.js library for writing TJBot recipes",
"version": "1.2.0",
"version": "1.2.1",
"author": "Justin Weisz <jweisz@us.ibm.com>",
"bugs": {
"url": "https://github.com/ibmtjbot/tjbotlib/issues"
Expand All @@ -14,7 +14,7 @@
"colornames": "^1.1.1",
"fifo": "^2.3.0",
"mic": "^2.1.1",
"node-raspistill": "0.0.9",
"node-raspistill": "^0.0.11",
"object.pick": "^1.2.0",
"semaphore": "^1.0.5",
"sleep": "^5.0.0",
Expand Down

0 comments on commit c250902

Please sign in to comment.