Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions client/camera/CameraMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ export default class CameraMain extends React.Component {
const colorsRGB = this.props.config.colorsRGB.slice();
colorsRGB[this.state.selectedColorIndex] = color.map(value => Math.round(value));

const paperDotSizes = this.props.config.paperDotSizes.slice();
paperDotSizes[this.state.selectedColorIndex] = size;

this.props.onConfigChange({ ...this.props.config, colorsRGB, paperDotSizes });
this.props.onConfigChange({ ...this.props.config, colorsRGB });
this.setState({ selectedColorIndex: -1 });
}}
debugPrograms={this.state.debugPrograms}
Expand Down
19 changes: 6 additions & 13 deletions client/camera/detectPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ export default function detectPrograms({
debugPrograms = [],
}) {
const startTime = Date.now();
const paperDotSizes = config.paperDotSizes;
const paperDotSizeVariance = // difference min/max size * 2
Math.max(1, Math.max.apply(null, paperDotSizes) - Math.min.apply(null, paperDotSizes)) * 2;
const avgPaperDotSize = paperDotSizes.reduce((sum, value) => sum + value) / paperDotSizes.length;
const markerSizeThreshold = avgPaperDotSize + paperDotSizeVariance;

const videoMat = new cv.Mat(videoCapture.video.height, videoCapture.video.width, cv.CV_8UC4);
videoCapture.read(videoMat);
Expand All @@ -187,7 +182,7 @@ export default function detectPrograms({

const videoROI = knobPointsToROI(config.knobPoints, videoMat);
const clippedVideoMat = videoMat.roi(videoROI);
let allPoints = simpleBlobDetector(clippedVideoMat, {
let keyPoints = simpleBlobDetector(clippedVideoMat, {
filterByCircularity: true,
minCircularity: 0.9,
minArea: 25,
Expand All @@ -197,7 +192,7 @@ export default function detectPrograms({
});

clippedVideoMat.delete();
allPoints.forEach(keyPoint => {
keyPoints.forEach(keyPoint => {
keyPoint.matchedShape = false; // is true if point has been recognised as part of a shape
keyPoint.pt.x += videoROI.x;
keyPoint.pt.y += videoROI.y;
Expand All @@ -208,10 +203,6 @@ export default function detectPrograms({
keyPoint.colorIndex || colorIndexForColor(keyPoint.avgColor, config.colorsRGB);
});

let [markers, keyPoints] = allBlobsAreKeyPoints
? [[], allPoints]
: partition(allPoints, ({ size }) => size > markerSizeThreshold);

// Sort by x position. We rely on this when scanning through the circles
// to find connected components, and when calibrating.
keyPoints = sortBy(keyPoints, keyPoint => keyPoint.pt.x);
Expand Down Expand Up @@ -301,7 +292,7 @@ export default function detectPrograms({
const avgKeyPointSize =
keyPointSizes.reduce((sum, value) => sum + value, 0) / keyPointSizes.length;

allPoints.forEach(keyPoint => {
keyPoints.forEach((keyPoint) => {
if (displayMat) {
if (config.showOverlayKeyPointCircles) {
// Draw circles around `keyPoints`.
Expand Down Expand Up @@ -436,7 +427,9 @@ export default function detectPrograms({
});

// Markers
markers = markers.map(({ colorIndex, avgColor, pt, size }) => {
const markers = keyPoints.filter((_, index) => {
return !seenIndexes.has(index);
}).map(({ colorIndex, avgColor, pt, size }) => {
const markerPosition = projectPointToUnitSquare(pt, videoMat, config.knobPoints);

const colorName = {
Expand Down
4 changes: 0 additions & 4 deletions client/camera/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import CameraMain from './CameraMain';
const defaultConfig = {
paperSize: 'LETTER',
colorsRGB: [[119, 43, 24, 255], [94, 104, 48, 255], [65, 80, 84, 255], [0, 0, 0, 255]],
paperDotSizes: [8, 8, 8, 8],
knobPoints: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 0, y: 1 }],
zoomTransform: d3.zoomIdentity,
showOverlayKeyPointCircles: true,
Expand All @@ -28,9 +27,6 @@ function sanitizeConfig(config) {
if (newConfig.colorsRGB.length !== defaultConfig.colorsRGB.length)
newConfig.colorsRGB = defaultConfig.colorsRGB;

if (!newConfig.paperDotSizes) {
newConfig.paperDotSizes = defaultConfig.paperDotSizes;
}
return newConfig;
}

Expand Down