本文整理汇总了C++中Scalar类的典型用法代码示例。如果您正苦于以下问题:C++ Scalar类的具体用法?C++ Scalar怎么用?C++ Scalar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scalar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cvtColor
void Feature::calcColorFeature()
{
// TODO: optimize this part, reduce extra work
Mat hsv;
cvtColor(mROI, hsv, CV_BGR2HSV_FULL);
Mat temp(mROI.size(), CV_8UC3), mixed;
Mat src[] = { mROI, mGray, hsv };
int fromTo[] = { 2,0, 3,1, 5,2 };
mixChannels(src, 3, &temp, 1, fromTo, 3);
temp.convertTo(mixed, CV_64F);
Scalar avg, stdDev;
meanStdDev(mixed, avg, stdDev, mMask);
Scalar var = stdDev.mul(stdDev);
Mat temp1 = mixed - avg;
Mat temp2 = temp1.mul(temp1);
Scalar sk = mean(temp1.mul(temp2), mMask) / (var.mul(stdDev));
Scalar ku = mean(temp2.mul(temp2), mMask) / (var.mul(var));
Scalar stat[] = { avg, stdDev, sk, ku };
for (int i = 0; i < 4; i++) {
red[i] = stat[i][0];
gray[i] = stat[i][1];
saturation[i] = stat[i][2];
}
}
示例2: WriteMemory
void
IRMemoryMap::WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Error &error)
{
error.Clear();
if (size == UINT32_MAX)
size = scalar.GetByteSize();
if (size > 0)
{
uint8_t buf[32];
const size_t mem_size = scalar.GetAsMemoryData (buf, size, GetByteOrder(), error);
if (mem_size > 0)
{
return WriteMemory(process_address, buf, mem_size, error);
}
else
{
error.SetErrorToGenericError();
error.SetErrorString ("Couldn't write scalar: failed to get scalar as memory data");
}
}
else
{
error.SetErrorToGenericError();
error.SetErrorString ("Couldn't write scalar: its size was zero");
}
return;
}
示例3: addScalar
void TimeAnalysisWidget::on_applyButton_clicked()
{
bool low = _ui->lowRadioButton->isChecked();
int numClusters = _ui->numClustersSpin->value();
std::vector<Point*> &points = low?_lowPoints.data():_highPoints.data();
std::vector<Point> centers;
std::vector<int> assignment;
PointClusterer::kmeans(PointClusterer::RANDOM,numClusters,
PointClusterer::EUCLIDEAN,
points, 10, centers, assignment);
std::ostringstream ss;
ss << "K-means " << numClusters << (low?" [low]":" [high]");
Scalar *scalar = addScalar(ss.str());
// create labels
scalar->labels().clear();
for (unsigned i=0; i<centers.size(); ++i) {
ss.str("");
ss << "Cluster [" << i << "]";
scalar->labels().push_back(ss.str());
}
// assigne scalar values to points
for (unsigned i=0; i<assignment.size(); ++i) {
Point *p = _lowPoints.data()[i];
p->setScalarValue(scalar, assignment[i]);
}
// refill combox
fillScalarComboBox();
_ui->colorByComboBox->setCurrentIndex(scalar->index());
}
示例4: TEST
TEST(ScalarTest, Division) {
Scalar lhs(5.0);
Scalar rhs(2.0);
Scalar r = lhs / rhs;
EXPECT_TRUE(r.IsValid());
EXPECT_EQ(r, Scalar(2.5));
}
示例5: exe_ctx
virtual bool
Execute
(
Args& command,
CommandReturnObject &result
)
{
DataExtractor reg_data;
ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext());
RegisterContext *reg_context = exe_ctx.GetRegisterContext ();
if (reg_context)
{
if (command.GetArgumentCount() != 2)
{
result.AppendError ("register write takes exactly 2 arguments: <reg-name> <value>");
result.SetStatus (eReturnStatusFailed);
}
else
{
const char *reg_name = command.GetArgumentAtIndex(0);
const char *value_str = command.GetArgumentAtIndex(1);
const RegisterInfo *reg_info = reg_context->GetRegisterInfoByName(reg_name);
if (reg_info)
{
Scalar scalar;
Error error(scalar.SetValueFromCString (value_str, reg_info->encoding, reg_info->byte_size));
if (error.Success())
{
if (reg_context->WriteRegisterValue(reg_info->kinds[eRegisterKindLLDB], scalar))
{
result.SetStatus (eReturnStatusSuccessFinishNoResult);
return true;
}
}
else
{
result.AppendErrorWithFormat ("Failed to write register '%s' with value '%s': %s\n",
reg_name,
value_str,
error.AsCString());
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendErrorWithFormat ("Register not found for '%s'.\n", reg_name);
result.SetStatus (eReturnStatusFailed);
}
}
}
else
{
result.AppendError ("no current frame");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
}
示例6: Cast_
template <typename Int> inline
float Cast_( const Scalar<Int>& s, ScalarType<float,Int> )
{
switch ( s.Type() ) {
default: TypeCastError( s.Type(), SINGLE );
case SINGLE: return s.template Get_<float>();
}
}
示例7: Equal
bool Scalar::Equal( Scalar& a, Scalar& b )
{
if( a.Type() != b.Type() )
return false;
DataType* pA = a.Get();
DataType* pB = b.Get();
return DataType::Equal( pA, pB );
}
示例8:
void
IM::multiply_assign (const Scalar& s, const Unit& u)
{
daisy_assert (unit_);
for (std::map<symbol, double>::iterator i = content.begin ();
i != content.end ();
i++)
(*i).second = Units::multiply (*unit_, s.unit (),
(*i).second * s.value (), u);
unit_ = &u;
}
示例9: value_sp
uint64_t
SBValue::GetValueAsUnsigned(uint64_t fail_value)
{
ValueLocker locker;
lldb::ValueObjectSP value_sp(GetSP(locker));
if (value_sp)
{
Scalar scalar;
if (value_sp->ResolveValue (scalar))
return scalar.ULongLong(fail_value);
}
return fail_value;
}
示例10: dolfin_error
//-----------------------------------------------------------------------------
double dolfin::assemble(const Form& a)
{
if (a.rank() != 0)
{
dolfin_error("assemble.cpp",
"assemble form",
"Expecting a scalar form but rank is %d",
a.rank());
}
Scalar s;
Assembler assembler;
assembler.assemble(s, a);
return s.get_scalar_value();
}
示例11: api_locker
uint64_t
SBValue::GetValueAsUnsigned(uint64_t fail_value)
{
if (m_opaque_sp)
{
if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
{
Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Scalar scalar;
if (m_opaque_sp->ResolveValue (scalar))
return scalar.GetRawBits64(fail_value);
}
}
return fail_value;
}
示例12: ReadIntegerArgument
static bool ReadIntegerArgument(Scalar &scalar, unsigned int bit_width,
bool is_signed, Thread &thread,
uint32_t *argument_register_ids,
unsigned int ¤t_argument_register,
addr_t ¤t_stack_argument) {
if (bit_width > 64)
return false; // Scalar can't hold large integer arguments
if (current_argument_register < 6) {
scalar = thread.GetRegisterContext()->ReadRegisterAsUnsigned(
argument_register_ids[current_argument_register], 0);
current_argument_register++;
if (is_signed)
scalar.SignExtend(bit_width);
} else {
uint32_t byte_size = (bit_width + (8 - 1)) / 8;
Status error;
if (thread.GetProcess()->ReadScalarIntegerFromMemory(
current_stack_argument, byte_size, is_signed, scalar, error)) {
current_stack_argument += byte_size;
return true;
}
return false;
}
return true;
}
示例13: AssignSum
bool Multivector::AssignSum( const Multivector& multivectorA, const Multivector& multivectorB )
{
if( this == &multivectorA && this == &multivectorB )
{
Scalar scalarTwo;
if( !scalarTwo.Assign( 2.0 ) )
return false;
if( !AssignScalarProduct( scalarTwo, *this ) )
return false;
return true;
}
bool accumulateA = true;
bool accumulateB = true;
if( this == &multivectorA )
accumulateA = false;
else if( this == &multivectorB )
accumulateB = false;
else
sumOfTerms.RemoveAll();
if( accumulateA )
{
for( const SumOfTerms::Node* node = multivectorA.sumOfTerms.Head(); node; node = node->Next() )
{
const Term* term = node->data;
sumOfTerms.InsertAfter()->data = term->Clone();
}
}
if( accumulateB )
{
for( const SumOfTerms::Node* node = multivectorB.sumOfTerms.Head(); node; node = node->Next() )
{
const Term* term = node->data;
sumOfTerms.InsertAfter()->data = term->Clone();
}
}
if( !CollectTerms( Term::OUTER_PRODUCT ) )
return false;
return true;
}
示例14: Scalar
Scalar *TimeAnalysisWidget::addScalar( std::string name ) {
int index = -1;
for ( unsigned i = 0; i < _scalars.size(); ++i )
if ( _scalars[i]->name() == name ) {
index = i;
break;
}
if ( index == -1 ) {
Scalar *scalar = new Scalar( name );
scalar->setIndex(_scalars.size());
_scalars.push_back( scalar );
return scalar;
} else {
return _scalars[index];
}
}
示例15: AssignInnerProduct
bool Multivector::AssignInnerProduct( const Multivector& multivectorA, const Multivector& multivectorB )
{
if( multivectorA.CountProductTypes( Term::GEOMETRIC_PRODUCT ) > 0 )
if( !const_cast< Multivector* >( &multivectorA )->CollectTerms( Term::OUTER_PRODUCT ) )
return false;
if( multivectorB.CountProductTypes( Term::GEOMETRIC_PRODUCT ) > 0 )
if( !const_cast< Multivector* >( &multivectorB )->CollectTerms( Term::OUTER_PRODUCT ) )
return false;
Multivector* multivectorResult = this;
Multivector multivectorStorage;
if( this == &multivectorA || this == &multivectorB )
multivectorResult = &multivectorStorage;
for( const SumOfTerms::Node* nodeA = multivectorA.sumOfTerms.Head(); nodeA; nodeA = nodeA->Next() )
{
const Term* termA = nodeA->data;
for( const SumOfTerms::Node* nodeB = multivectorB.sumOfTerms.Head(); nodeB; nodeB = nodeB->Next() )
{
const Term* termB = nodeB->data;
Multivector innerProductMultivector;
if( !termA->InnerProductMultiply( termB, innerProductMultivector ) )
return false;
Scalar scalar;
if( !scalar.AssignProduct( *termA->coeficient, *termB->coeficient ) )
return false;
if( !innerProductMultivector.AssignScalarProduct( scalar, innerProductMultivector ) )
return false;
multivectorResult->sumOfTerms.Absorb( &innerProductMultivector.sumOfTerms );
}
}
if( multivectorResult == &multivectorStorage )
return Assign( multivectorStorage );
return true;
}