diff --git a/deviceConfigs/behaviorCams.json b/deviceConfigs/behaviorCams.json index 2e18a3d..36d5cc0 100644 --- a/deviceConfigs/behaviorCams.json +++ b/deviceConfigs/behaviorCams.json @@ -8,7 +8,33 @@ "controlSettings": { } }, - + "WebCam-320x240": { + "sensor": "", + "frameRate": 30, + "width": 320, + "height": 240, + "isColor": true, + "controlSettings": { + } + }, + "WebCam-640x480": { + "sensor": "", + "frameRate": 30, + "width": 640, + "height": 480, + "isColor": true, + "controlSettings": { + } + }, + "WebCam-1280x720": { + "sensor": "", + "frameRate": 30, + "width": 1280, + "height": 720, + "isColor": true, + "controlSettings": { + } + }, "Minicam-Mono-XGA": { "qmlFile": "qrc:/behaviorCam.qml", "sensor": "MT9P031", diff --git a/deviceConfigs/miniscopes.json b/deviceConfigs/miniscopes.json index e1b6f31..2b956b6 100644 --- a/deviceConfigs/miniscopes.json +++ b/deviceConfigs/miniscopes.json @@ -54,7 +54,7 @@ "max": 100, "stepSize": 1, "displayValueScale": -2.55, - "displayValueOffset": 0, + "displayValueOffset": -255, "sendCommand": [ { "protocol": "I2C", diff --git a/source/backend.cpp b/source/backend.cpp index a27a9cb..791a014 100644 --- a/source/backend.cpp +++ b/source/backend.cpp @@ -167,7 +167,7 @@ backEnd::backEnd(QObject *parent) : for (int i = 0; i < unAvailableCodec.length(); i++) tempStr += unAvailableCodec[i] + ", "; - setUserConfigDisplay("Select a User Configuration file.\n\nAvailable compression Codecs on your computer are:\n" + m_availableCodecList + + setUserConfigDisplay("Select a User Configuration file.\n\nSupported devices are listed in the .json files in the deviceConfig folder.\n\nAvailable compression Codecs on your computer are:\n" + m_availableCodecList + "\n\nUnavailable compression Codes on your computer are:\n" + tempStr.chopped(2)); // QObject::connect(this, SIGNAL (userConfigFileNameChanged()), this, SLOT( handleUserConfigFileNameChanged() )); diff --git a/source/behaviorcam.cpp b/source/behaviorcam.cpp index aadb094..705a718 100644 --- a/source/behaviorcam.cpp +++ b/source/behaviorcam.cpp @@ -32,12 +32,12 @@ BehaviorCam::BehaviorCam(QObject *parent, QJsonObject ucBehavCam) : m_ucBehavCam = ucBehavCam; // hold user config for this Miniscope - parseUserConfigBehavCam(); - getBehavCamConfig(m_ucBehavCam["deviceType"].toString()); // holds specific Miniscope configuration + parseUserConfigBehavCam(); + // TODO: Handle cases where there is more than webcams and MiniCAMs - if (m_ucBehavCam["deviceType"].toString() == "WebCam") { + if (m_ucBehavCam["deviceType"].toString().toLower().contains("webcam")) { isMiniCAM = false; m_daqFrameNum = nullptr; } @@ -220,10 +220,14 @@ void BehaviorCam::parseUserConfigBehavCam() { m_roiBoundingBox[1] = m_ucBehavCam["ROI"].toObject()["topEdge"].toInt(-1); m_roiBoundingBox[2] = m_ucBehavCam["ROI"].toObject()["width"].toInt(-1); m_roiBoundingBox[3] = m_ucBehavCam["ROI"].toObject()["height"].toInt(-1); - - // TODO: Throw error is values are incorrect or missing } + else { + m_roiBoundingBox[0] = 0; + m_roiBoundingBox[1] = 0; + m_roiBoundingBox[2] = m_cBehavCam["width"].toInt(-1); + m_roiBoundingBox[3] = m_cBehavCam["height"].toInt(-1); + } } void BehaviorCam::sendInitCommands() @@ -285,7 +289,6 @@ void BehaviorCam::getBehavCamConfig(QString deviceType) { QJsonDocument d = QJsonDocument::fromJson(jsonFile.toUtf8()); QJsonObject jObj = d.object(); m_cBehavCam = jObj[deviceType].toObject(); - } void BehaviorCam::configureBehavCamControls() { @@ -605,19 +608,31 @@ void BehaviorCam::handleSetRoiClicked() void BehaviorCam::handleNewROI(int leftEdge, int topEdge, int width, int height) { + m_roiIsDefined = true; // First scale the local position values to pixel values m_roiBoundingBox[0] = round(leftEdge/m_ucBehavCam["windowScale"].toDouble(1)); m_roiBoundingBox[1] = round(topEdge/m_ucBehavCam["windowScale"].toDouble(1)); m_roiBoundingBox[2] = round(width/m_ucBehavCam["windowScale"].toDouble(1)); m_roiBoundingBox[3] = round(height/m_ucBehavCam["windowScale"].toDouble(1)); + if ((m_roiBoundingBox[0] + m_roiBoundingBox[2]) > m_cBehavCam["width"].toInt(-1)) { + // Edge is off screen + m_roiBoundingBox[2] = m_cBehavCam["width"].toInt(-1) - m_roiBoundingBox[0]; + sendMessage("Warning: Right edge of ROI drawn beyond right edge of video. If this is incorrect you can change the width and height values in deviceCnfigs/behaviorCams.json"); + } + if ((m_roiBoundingBox[1] + m_roiBoundingBox[3]) > m_cBehavCam["height"].toInt(-1)) { + // Edge is off screen + m_roiBoundingBox[3] = m_cBehavCam["height"].toInt(-1) - m_roiBoundingBox[1]; + sendMessage("Warning: Bottm edge of ROI drawn beyond bottom edge of video. If this is incorrect you can change the width and height values in deviceCnfigs/behaviorCams.json"); + + } + sendMessage("ROI Set to [" + QString::number(m_roiBoundingBox[0]) + ", " + QString::number(m_roiBoundingBox[1]) + ", " + QString::number(m_roiBoundingBox[2]) + ", " + QString::number(m_roiBoundingBox[3]) + "]"); - // TODO: Make sure ROI gets saved in meta data - // TODO: enable ROI button + // TODO: Correct ROI if out of bounds } diff --git a/source/main.cpp b/source/main.cpp index 8694615..83bf7d0 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -9,7 +9,7 @@ #include "backend.h" -#define VERSION_NUMBER "1.00" +#define VERSION_NUMBER "1.02" // TODO: have exit button close everything // For Window's deployment diff --git a/userConfigs/UserConfigExample_V4_BNO_Miniscope.json b/userConfigs/UserConfigExample_V4_BNO_Miniscope.json index 56abaab..33601ba 100644 --- a/userConfigs/UserConfigExample_V4_BNO_Miniscope.json +++ b/userConfigs/UserConfigExample_V4_BNO_Miniscope.json @@ -36,7 +36,7 @@ "filterBadData": true }, "streamHeadOrientation_OLD": true, - "deviceID": 0, + "deviceID": 1, "showSaturation": true, "compressionOptions": ["MJPG","MJ2C","XVID","FFV1"], "compression": "FFV1", diff --git a/userConfigs/UserConfigExample_WebCam.json b/userConfigs/UserConfigExample_WebCam.json index 50c1f06..db70d64 100644 --- a/userConfigs/UserConfigExample_WebCam.json +++ b/userConfigs/UserConfigExample_WebCam.json @@ -1,6 +1,6 @@ { "researcherName": "Dr_Miniscope", - "dataDirectory": "C:/Users/DBAharoni/Documents/Data", + "dataDirectory": "C:/Users/dbaha/Documents/Data", "directoryStructure": [ "researcherName", "experimentName", @@ -26,19 +26,20 @@ "cameras": [ { "deviceName": "BehavCam 0", - "deviceType": "WebCam", + "deviceType": "WebCam-1280x720", "deviceID": 0, "showSaturation": true, "ROI": { - "notes": "This defines the bounding box of the portion of the video that is saved to disk", - "leftEdge": 10, - "topEdge": 20, - "width": 300, - "height": 200 + "notes": "This defines the bounding box of the portion of the video that is saved to disk", + "note3": "Edge values are zero indexed", + "leftEdge": 0, + "topEdge": 0, + "width": 640, + "height": 480 }, "cameraCalibrationFileLocation": "", "compressionOptions": ["MJPG","MJ2C","XVID","FFV1"], - "compression": "FFV1", + "compression": "MJPG", "framesPerFile": 1000, "windowScale": 0.75, "windowX": 800,