Пример #1
0
bool provider_register(char *name, uint64_t channel_id)
{
  Feature *f = find_feature(name);

  if (!f) {
    return false;
  }

  if (f->channel_id && channel_exists(f->channel_id)) {
    ILOG("Feature \"%s\" is already provided by another channel"
         "(will be replaced)", name);
  }

  DLOG("Registering provider for \"%s\"", name);
  f->channel_id = channel_id;

  // Associate all method names with the feature struct
  size_t i;
  char *method;
  for (method = f->methods[i = 0]; method; method = f->methods[++i]) {
    pmap_put(cstr_t)(registered_providers, method, f);
    DLOG("Channel \"%" PRIu64 "\" will be sent requests for \"%s\"",
         channel_id,
         method);
  }

  ILOG("Registered channel %" PRIu64 " as the provider for the \"%s\" feature",
       channel_id,
       name);

  return true;
}
Пример #2
0
void CIMXML_Parser::_start_PROPERTY_ARRAY(const char** attrs)
{
    CIMXML_ASSUME(!_instances.empty());

    // NAME attribute:

    const char* name;

    if (_find_required_attr(attrs, "NAME", name) != 0)
        return;

    // TYPE attribute:

    Type type;

    if (_find_type_attr(attrs, "TYPE", type) != 0)
        return;

    // Set current meta feature:

    Working_Instance& wi = _instances.top();
    CIMXML_ASSUME(wi.instance != 0);

    wi.mf = find_feature(wi.instance->meta_class, name,
        CIMPLE_FLAG_PROPERTY | CIMPLE_FLAG_REFERENCE);
}
Пример #3
0
static int parse_feature(struct vzctl_features_param *features, const char *str)
{
	int id, len;
	const char *p;
	struct feature_s *f;
	char name[STR_SIZE];

	p = strrchr(str, ':');
	if (p == NULL)
		goto err;

	len = p - str;
	if (len >= sizeof(name))
		len = sizeof(name) - 1;
	strncpy(name, str, len);
	name[len] = 0;
	f = find_feature(name);
	if (f == NULL)
		goto err;

	id = onoff2id(p + 1);
	if (id == -1)
		goto err;
	if (id == VZCTL_PARAM_ON)
		features->mask |= f->mask;
	features->known |= f->mask;

	return 0;
err:

	return vzctl_err(VZCTL_E_INVAL, 0, "An incorrect feature syntax: %s", str);
}
Пример #4
0
CIMPLE_NAMESPACE_BEGIN

const Meta_Feature* find_feature(
    const Meta_Method* mm,
    const char* name,
    uint32 type)
{
    return find_feature((const Meta_Class*)mm, name, type);
}
Пример #5
0
static int run_feature_func(ocfs2_fs_options *feature, void *user_data)
{
    errcode_t err;
    struct run_features_context *ctxt = user_data;
    struct tunefs_feature *feat = find_feature(feature);

    err = tunefs_feature_run(ctxt->rc_fs, feat);
    if (err && (err != TUNEFS_ET_OPERATION_FAILED))
        tcom_err(err, "while toggling feature \"%s\"",
                 feat->tf_name);

    return err;
}
Пример #6
0
int main()
{	
	int t1= time(0);
	vector<vector<int> > ftr;
	ftr.resize(32384);
	for(int i = 0; i < 32384; i++)
		ftr[i].resize(4);
	find_feature(ftr);

	int T = 100;
	vector<weak_cla> ada; 
	ada.resize(T);
	ifstream input;
	input.open("ada.txt");
	for(int i = 0; i < 100; i++)
	{
		input>>ada[i].index>>ada[i].pol>>ada[i].alpha>>ada[i].theta;
	}
	input.close();

	Mat img = imread("../data/class_photo_2013.jpg");
	Mat gimg;
	cvtColor(img, gimg, CV_BGR2GRAY);
	vector<point> v;

	//bool ok = false;
	ofstream output;
	int size = 16;
	output.open("tem.txt");
	int b[5] = {64,50,32,16,20};
	double c[5] = {5, 3.5, 5, 5, 5};
	double d[5] = {11, 4.5, 11,11,11};
	for(int a = 4; a >= 0; a--)
	{
		size = b[a];
		cout<<size<<" "<<v.size()<<endl;
		for(int i = 200; i < gimg.rows - size/2; i+=size/4)
		{
			for(int j = 100; j < gimg.cols - size/2; j+=size/4)
			{
				Mat window(size, size, CV_8UC1);
				// get the window, min of window and max of window
				int min = INT_MAX, max = INT_MIN;
				for(int p = 0; p < size; p++)
				{
					for(int q = 0; q < size; q++)
					{
						window.at<uchar>(p,q) = gimg.at<uchar>(i-size/2+p,j-size/2+q);
						if(window.at<uchar>(p,q) < min)
							min = window.at<uchar>(p,q);
						if(window.at<uchar>(p,q) > max)
							max = window.at<uchar>(p,q);
					}
				}
				if(max - min < 80)
					continue;

				resize(window, window, Size(16,16), 0, 0, INTER_LINEAR);
				equalizeHist(window, window);

				//calculate the F(x)
				double tem_sum = 0;
				for(int k = 0; k < T; k++)
				{
					int f_value = feature_value(ada[k].index, window, ftr);
					tem_sum += ada[k].pol * ada[k].alpha * double(f_value - ada[k].theta >= 0 ? 1 : -1);
					//cout<<tem_sum<<endl;
				}
				if(tem_sum > 0)
					output<<i<<" "<<j<<" "<<tem_sum<<endl;
				if(tem_sum > c[a] && tem_sum < d[a])
				{
					cout<<i<<" "<<j<<" "<<v.size()<<" "<<tem_sum<<endl;
					bool ok = true;
					for(int k = 0; k < v.size(); k++)
					{
						if(i-size/2 >= v[k].x - v[k].num/2 && i+size/2 < v[k].x + v[k].num/2 && j-size/2 >= v[k].y - v[k].num/2 && j+size/2 < v[k].y + v[k].num/2)
						{
							ok = false;
							break;
						}
					}
					if(ok)
					{
						v.push_back(point(i,j,size));
					}
				}
			}
		}
	}
	output.close();
	
	for(int i = 0; i < v.size(); i++)
	{
		int x, y, n;
		x = v[i].x; y = v[i].y; n = v[i].num;
		int lx = x-n/2, ly = y-n/2;
		if(n % 2 == 0)
		{
			lx--;
			ly--;
		}
		rectangle(img, Point(ly,lx), Point(ly+n, lx+n), Scalar(0,255,255), 2, CV_AA);
	}
	imwrite("result.jpg", img);
	int t2 = time(0);
	cout<<"time "<<t2-t1<<endl;
	//waitKey();
	
  return 0;
}
Пример #7
0
bool provider_has_feature(char *name)
{
  Feature *f = find_feature(name);
  return f != NULL && channel_exists(f->channel_id);
}
Пример #8
0
/*
    Convert an instance from the adapter format to CIMPLE. Creates a new
    instance if inst is NULL. Only property and references are converted.
    This uses the adapter get_value(), get_size(), and get_name() functions
    to access the characteristics of each feature to be converted.
*/
int Container::convert(const Meta_Class* mc, uint32 flags, Instance*& inst)
{
    PENTRY("Container::convert");
    const char* cn = mc->name;

    // Create hew new instance (if incoming one is null) and nullify
    // all properties

    if (!inst)
        inst = create(mc);

    nullify_properties(inst);

    // get property count from the adapter

    size_t size = get_size();

    // for each feature in the adapter instance, get the name, match
    // with the Meta_Feature, filter features that do not match flags,
    // and get the feature value from the adapter and insert into the
    // CIMPLE instance

    for (size_t i = 0; i < size; i++)
    {
        // Get name of this feature from the adapter

        String name;

        if (get_name(i, name) != 0)
        {
            CIMPLE_WARN((
                "get_name() failed: class=%s, index=%u", cn, uint32(i)));
            continue;
        }

        const Meta_Feature* mf = find_feature(
            mc, name.c_str(), CIMPLE_FLAG_PROPERTY | CIMPLE_FLAG_REFERENCE);

        if (!mf)
        {
            CIMPLE_WARN(("unknown feature: %s.%s", cn, name.c_str()));
            continue;
        }

        // Filter features that do not match the flags.

        if (flags && !(mf->flags & flags))
            continue;

        // Get type:

        Value::Type type = type_of(mf);

        if (type == Value::NONE)
        {
            CIMPLE_WARN(("unexpected error: %s.%s", cn, name.c_str()));
            continue;
        }

        // Get value of this feature from adapter Useing the get_value()
        // defined by the adapter subclass to get the value from the adapter
        // feature

        Value value;

        if (get_value(i, type, value) != 0)
        {
            CIMPLE_WARN(("conversion error: %s.%s", cn, name.c_str()));
            continue;
        }

        // Assign value into instance.

        if (value.get(inst, mf) != 0)
        {
            CIMPLE_WARN(("conversion error: %s.%s", cn, name.c_str()));
            continue;
        }
    }
    PEXIT_RTN_VAL(0);
    return 0;
}
Пример #9
0
const Meta_Reference* find_reference(const Meta_Method* mm, const char* name)
{
    return (const Meta_Reference*)find_feature(mm, name, CIMPLE_FLAG_REFERENCE);
}
Пример #10
0
const Meta_Property* find_parameter(const Meta_Method* mm, const char* name)
{
    return (const Meta_Property*)find_feature(mm, name, CIMPLE_FLAG_PROPERTY);
}
Пример #11
0
/* Order doesn't actually matter here.  We just want to know that
 * tunefs supports this feature */
static int check_supported_func(ocfs2_fs_options *feature, void *user_data)
{
    int rc = 1;
    struct check_supported_context *ctxt = user_data;
    struct feature_op_state *state = ctxt->sc_state;
    struct tunefs_feature *feat = find_feature(feature);

    if (!feat) {
        errorf("One or more of the features in \"%s\" are not "
               "supported by this program\n",
               ctxt->sc_string);
        ctxt->sc_error = 1;
        goto out;
    }

    switch (ctxt->sc_action) {
    case FEATURE_ENABLE:
        if (!feat->tf_enable) {
            errorf("This program does not "
                   "support enabling feature "
                   "\"%s\"\n",
                   feat->tf_name);
            ctxt->sc_error = 1;
            goto out;
        }
        break;

    case FEATURE_DISABLE:
        if (!feat->tf_disable) {
            errorf("This program does not "
                   "support disabling feature "
                   "\"%s\"\n",
                   feat->tf_name);
            ctxt->sc_error = 1;
            goto out;
        }
        break;

    case FEATURE_NOOP:
        verbosef(VL_APP,
                 "Should have gotten a NOOP "
                 "action for feature \"%s\"\n",
                 feat->tf_name);
        rc = 0;
        goto out;
        break;

    default:
        errorf("Unknown action for feature \"%s\"\n",
               feat->tf_name);
        ctxt->sc_error = 1;
        goto out;
        break;
    }

    verbosef(VL_APP, "%s feature \"%s\"\n",
             ctxt->sc_action == FEATURE_ENABLE ?
             "Enabling" : "Disabling",
             feat->tf_name);
    feat->tf_action = ctxt->sc_action;
    state->fo_op->to_open_flags |= feat->tf_open_flags;

    rc = 0;

out:
    return rc;
}