bool operator==(const ::google::protobuf::RepeatedField<T>& a, const ::google::protobuf::RepeatedField<T>& b) { if (a.size() != b.size()) return false; for (auto aiter=a.begin(), biter=b.begin(); aiter != a.end(); aiter++, biter++ ) { if (*aiter != *biter) return false; } return true; }
Mat getMatFromTensor(opencv_onnx::TensorProto& tensor_proto) { CV_Assert(!tensor_proto.raw_data().empty() || !tensor_proto.float_data().empty() || !tensor_proto.double_data().empty() || !tensor_proto.int64_data().empty()); opencv_onnx::TensorProto_DataType datatype = tensor_proto.data_type(); Mat blob; std::vector<int> sizes; for (int i = 0; i < tensor_proto.dims_size(); i++) { sizes.push_back(tensor_proto.dims(i)); } if (sizes.empty()) sizes.assign(1, 1); if (datatype == opencv_onnx::TensorProto_DataType_FLOAT) { if (!tensor_proto.float_data().empty()) { const ::google::protobuf::RepeatedField<float> field = tensor_proto.float_data(); Mat(sizes, CV_32FC1, (void*)field.data()).copyTo(blob); } else { char* val = const_cast<char*>(tensor_proto.raw_data().c_str()); Mat(sizes, CV_32FC1, val).copyTo(blob); } } else if (datatype == opencv_onnx::TensorProto_DataType_DOUBLE) { const ::google::protobuf::RepeatedField<double> field = tensor_proto.double_data(); CV_Assert(!field.empty()); Mat(sizes, CV_64FC1, (void*)field.data()).convertTo(blob, CV_32FC1); } else if (datatype == opencv_onnx::TensorProto_DataType_INT64) { blob.create(sizes, CV_32SC1); int32_t* dst = reinterpret_cast<int32_t*>(blob.data); if (!tensor_proto.int64_data().empty()) { ::google::protobuf::RepeatedField< ::google::protobuf::int64> src = tensor_proto.int64_data(); convertInt64ToInt32(src, dst, blob.total()); } else { char* val = const_cast<char*>(tensor_proto.raw_data().c_str()); int64_t* src = reinterpret_cast<int64_t*>(val); convertInt64ToInt32(src, dst, blob.total()); } } else CV_Error(Error::StsUnsupportedFormat, "Unsupported data type: " + opencv_onnx::TensorProto_DataType_Name(datatype)); if (tensor_proto.dims_size() == 0) blob.dims = 1; // To force 1-dimensional cv::Mat for scalars. return blob; }
inline bool operator== ( const google::protobuf::RepeatedField<T> & x, const google::protobuf::RepeatedField<T> & y) { if (LOOM_UNLIKELY(x.size() != y.size())) { return false; } for (size_t i = 0, size = x.size(); i < size; ++i) { if (LOOM_UNLIKELY(x.Get(i) != y.Get(i))) { return false; } } return true; }
// Get an OSM tag for a given key (or return empty string if none) // Called from Lua string Find(const string& key) const { // First, convert the string into a number if (tagMap.find(key) == tagMap.end()) { return ""; } uint keyNum = tagMap.at(key); if (isWay) { // Then see if this number is in the way tags, and return its value if so for (uint n=0; n < tagLength; n++) { if (keysPtr->Get(n)==keyNum) { return stringTable[valsPtr->Get(n)]; } } } else { for (uint n=denseStart; n<denseEnd; n+=2) { if (densePtr->keys_vals(n)==keyNum) { return stringTable[densePtr->keys_vals(n+1)]; } } } return ""; }
// Check if there's a value for a given key // Called from Lua bool Holds(const string& key) const { if (tagMap.find(key) == tagMap.end()) { return false; } uint keyNum = tagMap.at(key); if (isWay) { for (uint n=0; n > tagLength; n++) { if (keysPtr->Get(n)==keyNum) { return true; } } } else { for (uint n=denseStart; n<denseEnd; n+=2) { if (densePtr->keys_vals(n)==keyNum) { return true; } } } return false; }