Commit 1576f85e authored by artificiel's avatar artificiel
Browse files

Initial commit

parents
#########################
# general patterns
#########################
docs/html
docs/tagfile.xml
*/bin/*
!*/bin/data/
# for bin folder in root
/bin/*
!/bin/data/
[Bb]uild/
[Oo]bj/
*.o
[Dd]ebug*/
[Rr]elease*/
*.mode*
*.app/
*.pyc
.svn/
#########################
# IDE
#########################
# XCode
*.pbxuser
*.perspective
*.perspectivev3
*.mode1v3
*.mode2v3
#XCode 4
xcuserdata
*.xcworkspace
# Code::Blocks
*.depend
*.layout
*.cbTemp
# Visual Studio
*.sdf
*.opensdf
*.suo
*.pdb
*.ilk
*.aps
ipch/
# Eclipse
.metadata
local.properties
.externalToolBuilders
# Codelite
*.session
*.tags
*.workspace.*
#########################
# operating system
#########################
# Linux
*~
# KDE
.directory
.AppleDouble
# OSX
.DS_Store
*.swp
*~.nib
# Thumbnails
._*
# Windows
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#Android
.csettings
#########################
# packages
#########################
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases
*.log
*.sql
*.sqlite
ofxRGVBHistogram
================
Introduction
------------
ofxRGVBHistogram provides a vectorial overlay with live red, green, blue and value (brightness) histograms calculated from an ofFbo. It is designed to be dropped-in. See the ofxFBODeluxe example.
Installation
------------
Basic addon; simply copy to the addons folder and #include "ofxRGVBHistogram.hpp".
Dependencies
------------
This addon builds on ofxHistogram and ofxFastFboReader
TODO
----
1. Under certain conditions the histograms appear too noisy. This seems to be linked to some harmonic relationship with the FFT bins or something in the ofxHistogram/openCV code... It is annoying but does not hamper the overall utility of watching the histograms to get a sense of the color energy in the image. Smoothing these lobish things would be good.
2. The image data being on the GPU, there must be an optimisation to use a (compute?) shader to do the equivalent process there... or maybe some fancy thread channel to prepare the graphs in a thread? but for our needs of the histograms (which are on the presetting / calibration side of things) using the CPU in the openGL thread is fine.
Compatibility
-------------
Tested against the rolling versions in git between june and december 2019.
Version history
---------------
### Version 0.1 (2020-01-01):
Initial release.
License
-------
MIT License. (c) 2020 alexandre burton / artificiel.org. See License.md for additional information.
meta:
ADDON_NAME = ofxRGBVHistogram
ADDON_DESCRIPTION = ofxRGBVHistogram overlays an R,G,V and B histograms on a running FBO
ADDON_AUTHOR = Alexandre Burton / artificiel.org
ADDON_TAGS = "addon" "histogram" "analysis"
ADDON_URL = http://github.com/artificiel/ofxRGBVHistogram
common:
ADDON_DEPENDENCIES = ofxHistogram
ADDON_DEPENDENCIES += ofxFastFboReader
#This file is currently only for linux users!
#Add your addon and all other necessary ones here (without '#')
#put every addon in one line, for example
#myAddon
#ofxXmlSettings
#ofxOpenCv
#include "ofApp.h"
int main(){
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofSetupOpenGL(1024, 768, OF_WINDOW);
ofRunApp(new ofApp());
}
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
#include "ofxAddonTemplate.h"
class ofApp: public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
};
The code in this repository is available under the [MIT License](https://secure.wikimedia.org/wikipedia/en/wiki/Mit_license).
Copyright (c) 2020 artificiel.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
#ifndef OFX_RGBVHISTOGRAM_HPP
#define OFX_RGBVHISTOGRAM_HPP
#include <algorithm>
#include <functional>
#include "ofMain.h"
#include "ofxFastFboReader.h"
#include "ofxHistogram.h"
#include "ofxOpenCv.h"
template <typename T>
std::vector<T> operator+(const std::vector<T>& a, const std::vector<T>& b)
{
assert(a.size() == b.size());
std::vector<T> result;
result.reserve(a.size());
std::transform(a.begin(), a.end(), b.begin(),
std::back_inserter(result), std::plus<T>());
return result;
}
class RGBVHistogram {
public:
void setup(int w, int h, size_t bins = 256)
{
bins_ = bins;
rgb_.allocate(w, h);
hsv_.allocate(w, h);
v.allocate(w, h);
r.allocate(w, h);
g.allocate(w, h);
b.allocate(w, h);
fbo_.allocate(w, h, GL_RGB);
}
void update()
{
update(fbo_);
}
void update(ofFbo& fbo)
{
ofPixels pixels;
reader_.readToPixels(fbo, pixels);
rgb_.setFromPixels(pixels);
cvCvtColor(rgb_.getCvImage(), hsv_.getCvImage(), CV_BGR2HSV);
r.setFromPixels(rgb_.getPixels().getChannel(0));
g.setFromPixels(rgb_.getPixels().getChannel(1));
b.setFromPixels(rgb_.getPixels().getChannel(2));
histogramR = histogram_.getHistogram(r, bins_);
histogramG = histogram_.getHistogram(g, bins_);
histogramB = histogram_.getHistogram(b, bins_);
// the hsv conversion is not cheap; this is a faster way to get a sense of the V
histogramV = histogramR + histogramG + histogramB;
}
void draw(int x, int y, int w, int h)
{
ofPushMatrix();
ofPushStyle();
{
ofTranslate(x, y);
ofEnableBlendMode(OF_BLENDMODE_ALPHA);
ofFill();
ofSetColor(0, 0, 0, 128);
ofDrawRectangle(0, 0, w, h);
fbo_.draw(w, h, w, h);
if (!histogramV.empty()) {
draw_histogram(histogramR, w, h, ofColor(255, 50, 50, 128), ofColor(200, 0, 0, 64));
draw_histogram(histogramG, w, h, ofColor(0, 175, 0, 128), ofColor(0, 255, 0, 64));
draw_histogram(histogramB, w, h, ofColor(64, 64, 255, 128), ofColor(0, 0, 255, 64));
draw_histogram(histogramV, w, h, ofColor(128, 128, 128, 128));
ofEnableBlendMode(OF_BLENDMODE_DISABLED);
// black peak
if ((histogramV[0] + histogramV[1] + histogramV[2] + histogramV[3]) > .01) {
ofFill();
ofSetColor(ofColor::black);
ofDrawRectangle(5, h - 10 - 5, 10, 10);
ofNoFill();
ofSetColor(ofColor::red);
ofDrawRectangle(5, h - 10 - 5, 10, 10);
}
// white peak
if (histogramV[histogramV.size() - 1] > 0.02) {
ofFill();
ofSetColor(ofColor::white);
ofDrawRectangle(w - 5 - 10, h - 10 - 5, 10, 10);
ofNoFill();
ofSetColor(ofColor::red);
ofDrawRectangle(w - 5 - 10, h - 10 - 5, 10, 10);
}
}
}
ofPopStyle();
ofPopMatrix();
}
void draw_histogram(vector<float>& h, int width, int height, ofColor line_color, ofColor fill_color = NULL)
{
if (fill_color != NULL) {
ofSetColor(fill_color);
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofBeginShape();
ofFill();
ofSetLineWidth(3);
for (size_t i = 0; i < h.size(); i++) {
float x = ofMap(i, 0, h.size() - 1, 0, width);
float y = ofMap(pow(h[i], .5), 0, 0.3, height, 0, true);
ofVertex(x, y);
}
ofVertex(width, height);
ofVertex(0, height);
ofEndShape();
}
ofSetColor(line_color);
ofEnableBlendMode(OF_BLENDMODE_DISABLED);
ofBeginShape();
ofNoFill();
ofSetLineWidth(3);
for (size_t i = 0; i < h.size(); i++) {
float x = ofMap(i, 0, h.size() - 1, 0, width);
float y = ofMap(sqrt(h[i]), 0, 0.3, height, 0, true);
ofVertex(x, y);
}
ofEndShape();
}
std::size_t bins_;
ofxFastFboReader reader_;
ofFbo fbo_;
ofxHistogram histogram_;
ofxCvColorImage rgb_, hsv_;
ofxCvGrayscaleImage r, g, b, v;
vector<float> histogramV, histogramR, histogramG, histogramB;
};
#endif // OFX_RGBVHISTOGRAM_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment