<commit_before>#pragma once

// OpenCV 2
#include "opencv2/opencv.hpp"

// ofxCv
#include "FloatImage.h"
#include "Distance.h"
#include "Calibration.h"

// openFrameworks
#include "ofConstants.h"
#include "ofImage.h"

#include "stdint.h"

/*
 there should be a few kinds of functions:
 1 utility functions like imitate and toCv
 2 wrapper functions that accept toCv-compatible objects
  
 all functions should guarantee the size of the output with imitate when necessary
 all output should be done using function arguments, to keep things flexible
 
 there should be a ton more const functions, but it's hard because of OF const issues
 need to print better errors than default opencv errors...?
 */

namespace ofxCv {

	using namespace cv;
	
	// 1 utility functions
	
	// imitate() is good for preparing buffers
	// it's like allocate(), but uses the size and type of the original as a reference
	void imitate(ofPixels& mirror, ofPixels& original);
	void imitate(ofImage& mirror, ofPixels& original);
	void imitate(FloatImage& mirror, ofPixels& original);
	void imitate(FloatImage& mirror, FloatImage& original);
	
	template <class T>
	void imitate(T& mirror, ofBaseHasPixels& original) {
		imitate(mirror, original.getPixelsRef());
	}
	
	void copy(Mat to, Mat from);
	
	// maximum possible values for that depth or matrix
	float getMaxVal(int depth);
	float getMaxVal(const Mat& mat);
	
	// toCv functions
	Mat toCv(Mat& mat);
	Mat toCv(ofPixels& pix);
	Mat toCv(ofBaseHasPixels& img);
	Mat toCv(FloatImage& img);
	Mat toCv(ofMesh& mesh);
	Point2f toCv(ofVec2f& vec);
	Point3f toCv(ofVec3f& vec);
	cv::Rect toCv(const ofRectangle& rect);
	int toCv(const ofImageType& ofType);
	
	// toOf functions
	ofVec2f toOf(Point2f point);
	ofVec3f toOf(Point3f point);
	ofRectangle toOf(cv::Rect rect);
	
	// 2 toCv-compatible wrappers
	
	// threshold out of place
	template <class SrcType, class DstType>
	void threshold(SrcType& src, DstType& dst, float thresholdValue, bool invert = false) {
		Mat srcMat = toCv(src);
		Mat dstMat = toCv(dst);
		int thresholdType = invert ? THRESH_BINARY_INV : THRESH_BINARY;
		float maxVal = getMaxVal(dstMat);
		cv::threshold(srcMat, dstMat, thresholdValue, maxVal, thresholdType);
	}
	
	// threshold in place
	template <class SrcDstType>
	void threshold(SrcDstType& srcDst, float thresholdValue, bool invert = false) {
		threshold(srcDst, srcDst, thresholdValue, invert);
	}
	
	// CV_RGB2GRAY, CV_HSV2RGB, etc. with [RGB, BGR, GRAY, HSV, HLS, XYZ, YCrCb, Lab, Luv]
	template <class SrcType, class DstType>
	void convertColor(SrcType& src, DstType& dst, int code) {
		Mat srcMat = toCv(src);
		Mat dstMat = toCv(dst);
		cvtColor(srcMat, dstMat, code);<commit_msg>added wrappers for max, min, multiply, divide, add, subtract, absdiff, bitwise_and, bitwise_or, bitwise_xor. these are all functions of the form z = f(x, y) and can be wrapped with a single macro.<commit_after>#pragma once

// OpenCV 2
#include "opencv2/opencv.hpp"

// ofxCv
#include "FloatImage.h"
#include "Distance.h"
#include "Calibration.h"

// openFrameworks
#include "ofConstants.h"
#include "ofImage.h"

#include "stdint.h"

/*
 there should be a few kinds of functions:
 1 utility functions like imitate and toCv
 2 wrapper functions that accept toCv-compatible objects
  
 all functions should guarantee the size of the output with imitate when necessary
 all output should be done using function arguments, to keep things flexible
 
 there should be a ton more const functions, but it's hard because of OF const issues
 need to print better errors than default opencv errors...?
 */

namespace ofxCv {

	using namespace cv;
	
	// 1 utility functions
	
	// imitate() is good for preparing buffers
	// it's like allocate(), but uses the size and type of the original as a reference
	void imitate(ofPixels& mirror, ofPixels& original);
	void imitate(ofImage& mirror, ofPixels& original);
	void imitate(FloatImage& mirror, ofPixels& original);
	void imitate(FloatImage& mirror, FloatImage& original);
	
	template <class T>
	void imitate(T& mirror, ofBaseHasPixels& original) {
		imitate(mirror, original.getPixelsRef());
	}
	
	void copy(Mat to, Mat from);
	
	// maximum possible values for that depth or matrix
	float getMaxVal(int depth);
	float getMaxVal(const Mat& mat);
	
	// toCv functions
	Mat toCv(Mat& mat);
	Mat toCv(ofPixels& pix);
	Mat toCv(ofBaseHasPixels& img);
	Mat toCv(FloatImage& img);
	Mat toCv(ofMesh& mesh);
	Point2f toCv(ofVec2f& vec);
	Point3f toCv(ofVec3f& vec);
	cv::Rect toCv(const ofRectangle& rect);
	int toCv(const ofImageType& ofType);
	
	// toOf functions
	ofVec2f toOf(Point2f point);
	ofVec3f toOf(Point3f point);
	ofRectangle toOf(cv::Rect rect);
	
	// 2 toCv-compatible wrappers
	
	// wrapThree are functions that operate on three Mat objects. the first two
	// are inputs, and the third is an output. for example, the min() function:
	// min(x, y, result) will calculate the per-element min between x and y, and
	// store it in result.
	#define wrapThree(name) \
	template <class X, class Y, class Result>\
	void name(X& x, Y& y, Result& result) {\
		Mat xMat = toCv(x);\
		Mat yMat = toCv(y);\
		Mat resultMat = toCv(result);\
		cv::name(xMat, yMat, resultMat);\
	}
	wrapThree(max);
	wrapThree(min);
	wrapThree(multiply);
	wrapThree(divide);
	wrapThree(add);
	wrapThree(subtract);
	wrapThree(absdiff);
	wrapThree(bitwise_and);
	wrapThree(bitwise_or);
	wrapThree(bitwise_xor);
		
	// threshold out of place
	template <class SrcType, class DstType>
	void threshold(SrcType& src, DstType& dst, float thresholdValue, bool invert = false) {
		Mat srcMat = toCv(src);
		Mat dstMat = toCv(dst);
		int thresholdType = invert ? THRESH_BINARY_INV : THRESH_BINARY;
		float maxVal = getMaxVal(dstMat);
		cv::threshold(srcMat, dstMat, thresholdValue, maxVal, thresholdType);
	}
	
	// threshold in place
	template <class SrcDstType>
	void threshold(SrcDstType& srcDst, float thresholdValue, bool invert = false) {
		threshold(srcDst, srcDst, thresholdValue, invert);
	}
	
	// CV_RGB2GRAY, CV_HSV2RGB, etc. with [RGB, BGR, GRAY, HSV, HLS, XYZ, YCrCb, Lab, Luv]
	template <class SrcType, class DstType>
	void convertColor(SrcType& src, DstType& dst, int code) {
		Mat srcMat = toCv(src);
		Mat dstMat = toCv(dst);
		cvtColor(srcMat, dstMat, code);
{'fraction_non_alphanumeric': 0.1038774533269507, 'fraction_numerical': 0.005106111377054412, 'mean_word_length': 4.4982456140350875, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1294221', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2125, 'n_words': 721}