KafkaConsumer receives other data (DelphiKafkaClient) - delphi

With DelphiKafkaClient I tested this code:
ABytes := TFile.ReadAllBytes('d:\red.bmp')
FKafkaProducer.Produce(edtTopic.Text, #abytes, length(ABytes))
//bytes: 66, 77, 186, 1, ...
But in TfrmConsume.Start, line 183 the content differs:
MsgRec.Data := TKafkaUtils.PointerToBytes(Msg.payload, Msg.len)
//bytes 152, 231, 229, 8, ...
However, both data lengths match! What am I doing wrong?

Related

Delphi Request.ContentFields.Values['something'] is not showing values on MIME data

In TWebModule1.WebModule1WebActionItem1Action(), using Request.ContentFields.Values['content'] or any name, I cannot get any values from the POST, but if I use Request.ContentFields.DelimitedText, I will get the values. Where did I go wrong?
This is the values DelimitedText returned:
------WebKitFormBoundaryHkgxkABfO4DL8g8Q,"Content-Disposition: form-data; name=""name""",NEWTEST,------WebKitFormBoundaryHkgxkABfO4DL8g8Q,"Content-Disposition: form-data; name=""content""","{""resolution""",D,",""symbol_type""",stock,",""exchange""",IDX,",""listed_exchange""",IDX,",""symbol""",BBCA,",""short_name""",BBCA,",""legs""",[{\,"symbol\"":\""","BCA\"",\""","ro_symbol\"":\""","BCA\""}]""",id,":2,""name""",NEWTEST,",""description""",,",""charts_symbols""",{\,"1\"":{\""","ymbol\"":\""","BCA\""}}""",is_realtime,":""1""",content,":""{\""","ame\"":\""","EWTEST\"",\""","ayout\"":\""","\"",\""","harts\"":[{\""","anes\"":[{\""","ources\"":[{\""","ype\"":\""","ainSeries\"",\""","d\"":\""","NUxsv\"",\""","tate\"":{\""","tyle\"":8,\""","sdShowDividends\"":true,\""","sdShowSplits\"":true,\""","sdShowEarnings\"":true,\""","sdShowBreaks\"":false,\""","sdFlagSize\"":2,\""","howCountdown\"":false,\""","idAsk\"":{\""","isible\"":false,\""","ineStyle\"":1,\""","ineWidth\"":1,\""","idLineColor\"":\""","2962FF\"",\""","skLineColor\"":\""","F7525F\""},\""","rePostMarket\"":{\""","isible\"":true,\""","ineStyle\"":1,\""","ineWidth\"":1,\""","reMarketColor\"":\""","fb8c00\"",\""","ostMarketColor\"":\""","2962FF\""},\""","ighLowAvgPrice\"":{\""","ighLowPriceLinesVisible\"":false,\""","ighLowPriceLabelsVisible\"":false,\""","verageClosePriceLineVisible\"":false,\""","verageClosePriceLabelVisible\"":false},\""","howInDataWindow\"":true,\""","isible\"":true,\""","howPriceLine\"":true,\""","riceLineWidth\"":1,\""","riceLineColor\"":\""",",\","baseLineColor\"":\""","B2B5BE\"",\""","howPrevClosePriceLine\"":false,\""","revClosePriceLineWidth\"":1,\""","revClosePriceLineColor\"":\""","gba( 85, 85, 85, 1)\"",\""","inTick\"":\""","efault\"",\""","ividendsAdjustment\"":{},\""","ackAdjustment\"":false,\""","ettlementAsClose\"":true,\""","essionId\"":\""","egular\"",\""","essVis\"":false,\""","tatusViewStyle\"":{\""","ontSize\"":17,\""","howExchange\"":true,\""","howInterval\"":true,\""","ymbolTextSource\"":\""","escription\"",\""","howSymbolAsDescription\"":false},\""","andleStyle\"":{\""","pColor\"":\""","53b987\"",\""","ownColor\"":\""","eb4d5c\"",\""","rawWick\"":true,\""","rawBorder\"":true,\""","orderColor\"":\""","378658\"",\""","orderUpColor\"":\""","53b987\"",\""","orderDownColor\"":\""","eb4d5c\"",\""","ickColor\"":\""","737375\"",\""","ickUpColor\"":\""","a9cdd3\"",\""","ickDownColor\"":\""","f5a6ae\"",\""","arColorsOnPrevClose\"":false,\""","rawBody\"":true},\""","ollowCandleStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","rawWick\"":true,\""","rawBorder\"":true,\""","orderColor\"":\""","gba( 55, 134, 88, 1)\"",\""","orderUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","orderDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","ickColor\"":\""","gba( 115, 115, 117, 1)\"",\""","ickUpColor\"":\""","gba( 169, 220, 195, 1)\"",\""","ickDownColor\"":\""","gba( 245, 166, 174, 1)\"",\""","rawBody\"":true},\""","aStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","rawWick\"":true,\""","rawBorder\"":true,\""","orderColor\"":\""","gba( 55, 134, 88, 1)\"",\""","orderUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","orderDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","ickColor\"":\""","gba( 115, 115, 117, 1)\"",\""","ickUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ickDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","howRealLastPrice\"":false,\""","arColorsOnPrevClose\"":false,\""","nputs\"":{},\""","nputInfo\"":{},\""","rawBody\"":true},\""","arStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","arColorsOnPrevClose\"":false,\""","ontDrawOpen\"":false,\""","hinBars\"":true},\""","iloStyle\"":{\""","olor\"":\""","2962FF\"",\""","howBorders\"":true,\""","orderColor\"":\""","2962FF\"",\""","howLabels\"":true,\""","abelColor\"":\""","2962FF\"",\""","ontSize\"":7,\""","rawBody\"":true},\""","ineStyle\"":{\""","olor\"":\""","gba( 60, 120, 216, 1)\"",\""","inestyle\"":0,\""","inewidth\"":1,\""","riceSource\"":\""","lose\"",\""","tyleType\"":2},\""","reaStyle\"":{\""","olor1\"":\""","gba( 96, 96, 144, 0.5)\"",\""","olor2\"":\""","gba( 1, 246, 245, 0.5)\"",\""","inecolor\"":\""","gba( 0, 148, 255, 1)\"",\""","inestyle\"":0,\""","inewidth\"":1,\""","riceSource\"":\""","lose\"",\""","ransparency\"":50},\""","enkoStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","orderUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","orderDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","pColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","ownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","orderUpColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","orderDownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","ickUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ickDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","nputs\"":{\""","ource\"":\""","lose\"",\""","ources\"":\""","lose\"",\""","oxSize\"":3,\""","tyle\"":\""","TR\"",\""","trLength\"":14,\""","icks\"":true},\""","nputInfo\"":{\""","ource\"":{\""","ame\"":\""","ource\""},\""","ources\"":{\""","ame\"":\""","ource\""},\""","oxSize\"":{\""","ame\"":\""","ox size\""},\""","tyle\"":{\""","ame\"":\""","tyle\""},\""","trLength\"":{\""","ame\"":\""","TR Length\""},\""","icks\"":{\""","ame\"":\""","icks\""}}},\""","bStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","orderUpColor\"":\""","gba( 83, 185, 135, 1)\"",\""","orderDownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","pColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","ownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","orderUpColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","orderDownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","nputs\"":{\""","ource\"":\""","lose\"",\""","b\"":3},\""","nputInfo\"":{\""","ource\"":{\""","ame\"":\""","ource\""},\""","b\"":{\""","ame\"":\""","umber of line\""}}},\""","agiStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","pColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","ownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","nputs\"":{\""","ource\"":\""","lose\"",\""","tyle\"":\""","TR\"",\""","trLength\"":14,\""","eversalAmount\"":1},\""","nputInfo\"":{\""","ource\"":{\""","ame\"":\""","ource\""},\""","tyle\"":{\""","ame\"":\""","tyle\""},\""","trLength\"":{\""","ame\"":\""","TR Length\""},\""","eversalAmount\"":{\""","ame\"":\""","eversal amount\""}}},\""","nfStyle\"":{\""","pColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ownColor\"":\""","gba( 255, 77, 92, 1)\"",\""","pColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","ownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","nputs\"":{\""","ources\"":\""","lose\"",\""","eversalAmount\"":3,\""","oxSize\"":1,\""","tyle\"":\""","TR\"",\""","trLength\"":14,\""","neStepBackBuilding\"":false},\""","nputInfo\"":{\""","ources\"":{\""","ame\"":\""","ource\""},\""","oxSize\"":{\""","ame\"":\""","ox size\""},\""","eversalAmount\"":{\""","ame\"":\""","eversal amount\""},\""","tyle\"":{\""","ame\"":\""","tyle\""},\""","trLength\"":{\""","ame\"":\""","TR Length\""},\""","neStepBackBuilding\"":{\""","ame\"":\""","ne step back building\""}}},\""","aselineStyle\"":{\""","aselineColor\"":\""","gba( 117, 134, 150, 1)\"",\""","opFillColor1\"":\""","gba( 83, 185, 135, 0.1)\"",\""","opFillColor2\"":\""","gba( 83, 185, 135, 0.1)\"",\""","ottomFillColor1\"":\""","gba( 235, 77, 92, 0.1)\"",\""","ottomFillColor2\"":\""","gba( 235, 77, 92, 0.1)\"",\""","opLineColor\"":\""","gba( 83, 185, 135, 1)\"",\""","ottomLineColor\"":\""","gba( 235, 77, 92, 1)\"",\""","opLineWidth\"":1,\""","ottomLineWidth\"":1,\""","riceSource\"":\""","lose\"",\""","ransparency\"":50,\""","aseLevelPercentage\"":50},\""","angeStyle\"":{\""","pColor\"":\""","22AB94\"",\""","ownColor\"":\""","F7525F\"",\""","hinBars\"":true,\""","pColorProjection\"":\""","gba( 169, 220, 195, 1)\"",\""","ownColorProjection\"":\""","gba( 245, 166, 174, 1)\"",\""","nputs\"":{\""","ange\"":10,\""","hantomBars\"":false},\""","nputInfo\"":{\""","ange\"":{\""","ame\"":\""","ange\""},\""","hantomBars\"":{\""","ame\"":\""","hantom bars\""}}},\""","ilentIntervalChange\"":false,\""","ymbol\"":\""","BCA\"",\""","hortName\"":\""","BCA\"",\""","imeframe\"":\""",",\","onWidget\"":false,\""","nterval\"":\""","\"",\""","nitId\"":null,\""","urrencyId\"":\""","DR\"",\""","howSessions\"":false,\""","riceAxisProperties\"":{\""","utoScale\"":true,\""","utoScaleDisabled\"":false,\""","ockScale\"":false,\""","ercentage\"":false,\""","ercentageDisabled\"":false,\""","og\"":false,\""","ogDisabled\"":false,\""","lignLabels\"":true,\""","sInverted\"":false,\""","ndexedTo100\"":false}},\""","order\"":0,\""","aStyle\"":{\""","tudyId\"":\""","arSetHeikenAshi#tv-basicstudies-60\""},\""","enkoStyle\"":{\""","tudyId\"":\""","arSetRenko#tv-prostudies-40\""},\""","bStyle\"":{\""","tudyId\"":\""","arSetPriceBreak#tv-prostudies-34\""},\""","agiStyle\"":{\""","tudyId\"":\""","arSetKagi#tv-prostudies-34\""},\""","nfStyle\"":{\""","tudyId\"":\""","arSetPnF#tv-prostudies-34\""},\""","angeStyle\"":{\""","tudyId\"":\""","arSetRange#tv-basicstudies-72\""}},{\""","ype\"":\""","tudy_Volume\"",\""","d\"":\""","InSIU\"",\""","tate\"":{\""","tyles\"":{\""","ol\"":{\""","inestyle\"":0,\""","inewidth\"":1,\""","lottype\"":5,\""","rackPrice\"":false,\""","ransparency\"":50,\""","isible\"":true,\""","olor\"":\""","000080\"",\""","istogramBase\"":0,\""","oinPoints\"":false,\""","itle\"":\""","olume\""},\""","ol_ma\"":{\""","inestyle\"":0,\""","inewidth\"":1,\""","lottype\"":0,\""","rackPrice\"":false,\""","ransparency\"":0,\""","isible\"":false,\""","olor\"":\""","2196f3\"",\""","istogramBase\"":0,\""","oinPoints\"":false,\""","itle\"":\""","olume MA\""},\""","moothedMA\"":{\""","inestyle\"":0,\""","inewidth\"":1,\""","lottype\"":0,\""","rackPrice\"":false,\""","ransparency\"":0,\""","isible\"":false,\""","olor\"":\""","2196f3\"",\""","istogramBase\"":0,\""","oinPoints\"":false,\""","itle\"":\""","moothed MA\""}},\""","alettes\"":{\""","olumePalette\"":{\""","olors\"":{\""","\"":{\""","olor\"":\""","F7525F\"",\""","idth\"":1,\""","tyle\"":0,\""","ame\"":\""","alling\""},\""","\"":{\""","olor\"":\""","22AB94\"",\""","idth\"":1,\""","tyle\"":0,\""","ame\"":\""","rowing\""}}}},\""","nputs\"":{\""","howMA\"":false,\""","ength\"":20,\""","ol_prev_close\"":false,\""","ymbol\"":\""",",\","smoothingLine\"":\""","MA\"",\""","moothingLength\"":9},\""","recision\"":\""","efault\"",\""","ands\"":{},\""","rea\"":{},\""","raphics\"":{},\""","howInDataWindow\"":true,\""","isible\"":true,\""","howLegendValues\"":true,\""","howLabelsOnPriceScale\"":true,\""","lots\"":{\""","\"":{\""","d\"":\""","ol\"",\""","ype\"":\""","ine\""},\""","\"":{\""","d\"":\""","olumePalette\"",\""","alette\"":\""","olumePalette\"",\""","arget\"":\""","ol\"",\""","ype\"":\""","olorer\""},\""","\"":{\""","isible\"":true,\""","utureOnly\"":true,\""","reaks\"":{\""","olor\"":\""","gba(85, 85, 85, 1)\"",\""","isible\"":false,\""","tyle\"":2,\""","idth\"":1}},\""","radingProperties\"":{\""","howPositions\"":true,\""","ositionPL\"":{\""","isibility\"":true,\""","isplay\"":0},\""","howOrders\"":true,\""","howExecutions\"":true,\""","howReverse\"":true,\""","orizontalAlignment\"":2,\""","xtendLeft\"":true,\""","ineLength\"":5,\""","ineWidth\"":1,\""","ineStyle\"":2},\""","riceScaleSelectionStrategyName\"":\""","uto\""},\""","ineToolsGroups\"":{\""","roups\"":[]},\""","ersion\"":3,\""","imezone\"":\""","tc/UTC\"",\""","essions\"":{\""","roperties\"":{\""","raphics\"":{\""","ackgrounds\"":{\""","utOfSession\"":{\""","olor\"":\""","2962FF\"",\""","ransparency\"":92,\""","isible\"":false},\""","reMarket\"":{\""","olor\"":\""","FF9800\"",\""","ransparency\"":92,\""","isible\"":false},\""","ostMarket\"":{\""","olor\"":\""","2962FF\"",\""","ransparency\"":92,\""","isible\"":false}},\""","ertlines\"":{\""","essBreaks\"":{\""","olor\"":\""","4985e7\"",\""","tyle\"":2,\""","isible\"":false,\""","idth\"":1}}}}},\""","houldBeSavedEvenIfHidden\"":true,\""","hartId\"":\""","\""}]}""",------WebKitFormBoundaryHkgxkABfO4DL8g8Q,"Content-Disposition: form-data; name=""symbol""",BBCA,------WebKitFormBoundaryHkgxkABfO4DL8g8Q,"Content-Disposition: form-data; name=""resolution""",D,------WebKitFormBoundaryHkgxkABfO4DL8g8Q--
I have been googling the whole web, mostly outdated answer from years ago and I don't find any proper easy way to parse it, but I found my own manual way, please anyone, have a better way to parse please share. thanks.
LBoundary := ExtractHeaderSubItem(Request.ContentType, 'boundary', QuoteHTTP);
tmpstring := Request.Content;
tmpstring := trim(tmpstring);
i := Pos('Content-Disposition: form-data; name="name"', tmpstring);
j := Pos('Content-Disposition: form-data; name="content"', tmpstring);
k := j - i;
tmpstring := (Copy(tmpstring, i, k));
tmpstring := StringReplace(tmpstring, 'Content-Disposition: form-data; name="name"', '', [rfReplaceAll]);
tmpstring := StringReplace(tmpstring, 'Content-Disposition: form-data; name="content"', '', [rfReplaceAll]);
tmpstring := StringReplace(tmpstring, '--'+LBoundary, '', [rfReplaceAll]);
tmpstring := StringReplace(tmpstring, #13#10, '', [rfReplaceAll]);
tmpstring := StringReplace(tmpstring, #32, '', [rfReplaceAll]);
tmpstring := StringReplace(tmpstring, #9, '', [rfReplaceAll]);
name:= tmpstring;

how to convert 8-bit unsigned int data to signed?

I am getting List of 8-bit unsigned int from a mic source for each sample rate which looks like this
[61, 251, 199, 251, 56, 252, 138, 252, 211, 252, 18, 253, 91, 253, 194, 253, 25, 254, 54, 254, 19, 254, 190, 253, 80, 253, 249, 252, 233, 252, 46, 253, 180, 253, 54, 254, 136, 254, 157, 254, 110, 254, 38, 254, 208, 253, 117, 253, 68, 253, 57, 253, 83, 253, 163, 253, 20, 254, 151, 254, 51, 255, 215, 255, 105, 0, 207, 0, 246, 0, 249, 0, 10, 1, 64, 1, 162, 1, 4, 2, 64, 2, 97, 2, 111, 2, 110, 2, 89, 2, 40, 2, 241, 1, 199, 1, 178, 1, 192, 1, 241, 1, 45, 2, 77, 2, 70, 2, 45, 2, 36, 2, 83, 2, 176, 2, 21, 3, 121, 3, 229, 3, 87, 4, 185, 4, 225, 4, 197, 4, 129, 4, 26, 4, 150, 3, 7, 3, 128, 2, 55, 2, 65, 2, 134, 2, 223, 2, 25, 3, 41, 3, 28, 3, 255, 2, 234, 2, 240, 2, 25, 3, 62, 3, 92, 3, 146, 3, 219, 3, 65, 4, 149, 4, 164, 4, 130, 4, 51, 4, 195, 3, 69, 3, 164, 2, 244, 1, 75, 1, 187, 0, 81, 0, 240, 255, 135, 255, 19, 255, 155, 254, 64, 254, 22, 254, 58, 254, 146, 254, 217, 254, 248, 254, 215, 254, 144, 254, 92, 254, 84, 254, 141, 254, 229, 254, 39, 255, 96, 255, 170, 255, 248, 255, 69, 0, 117, 0, 128, 0, 137, 0, 131, 0,
so how can I convert this into signed decimal value or someone can guide me to the right path
That depends on what the bytes mean.
Looking at the bytes, every other byte is either very low or very high. That suggests to me that the bytes are really little-endian signed 16-bit values.
In that case, you just need to view them as such. If we assume that the platform is little-endian (most are), you can just do:
List<int> list = ...;
Uint8List bytes = Uint8List.fromList(list); //
Int16List words = Int16List.sublistView(bytes);
Then the words list contains signed 16-bit numbers.
(If the list is already a Uint8List, you can skip the first step.)
If that's not what the bytes mean, you'll have to figure out what they do mean.
Dart int type provide a method to convert from signed to unsigned and from unsigned to signed.
For example:
int a = 16;
int b = 239;
print(a.toSigned(5).toString()); // Print -16
print(b.toSigned(5).toString()); // Print 15
the toSigned method parameter indicate the bit order of the sign bit.
You can get more information here: https://api.flutter.dev/flutter/dart-core/int/toSigned.html
A toUnsigned method exixts too: https://api.flutter.dev/flutter/dart-core/int/toUnsigned.html

How to read byte array data in Dart?

connecting TCP Socket server and sending Request. and also Server sends the response in Byte array. How to read byte array data in dart.
Socket.connect('localhost', 8081)
.then((socket) {
//Establish the onData, and onDone callbacks
socket.listen((data) {
print(new String.fromCharCodes(data).trim()); //Here data is byte[]
//How to read byte array data
},
onDone: () {
print("Done");
// socket.destroy();
},
onError: (e) {
print('Server error: $e');
});
socket.add([255, 12, 0, 11, 0, 9, 34, 82, 69, 70, 84, 65, 72, 73, 76]);
});
}
It depends on with data type was encoded to bytes. Let's suppose it's String
Then you can do it with dart:convert library.
import 'dart:convert' show utf8;
final decoded = utf8.decode(data);
It's pretty clear that there's a message structure in those bytes. You give two examples of messages:
[255, 12, 0, 11, 0, 9, 34, 82, 69, 70, 84, 65, 72, 73, 76]
and
[255, 20, 0, 11, 0, 0, 0, 15, 80, 82, 69, 77, 84, 65, 72, 73, 76, 45, 53, 53, 57, 55, 48]
Both start with 255, followed by what looks like two or three little endian 16 bit words (12 and 11) and (20, 11 and 0) followed by a string, who's length is encoded in a leading byte. If you are expected to inter-operate with another system, you really need the protocol spec.
Assuming I've guessed the structure correctly, this code
main() {
Uint8List input = Uint8List.fromList([
255,
20,
0,
11,
0,
0,
0,
15,
80,
82,
69,
77,
84,
65,
72,
73,
76,
45,
53,
53,
57,
55,
48
]);
ByteData bd = input.buffer.asByteData();
print(bd.getUint16(1, Endian.little)); // print the first short
print(bd.getUint16(3, Endian.little)); // and the second
print(bd.getUint16(5, Endian.little)); // and the third
int stringLength = input[7]; // get the length of the string
print(utf8.decode(input.sublist(8, 8 + stringLength))); // decode the string
}
produces
20
11
0
PREMTAHIL-55970
as expected

Finding hamming distance between ORB feature descriptors

I am trying to write a function to match ORB features. I am not using default matchers (bfmatcher, flann matcher) because i just want match speific features in image with features in other image.
I saw ORS descriptor its a binary array.
My query is how to match 2 features i.e how to find hamming distance between 2 descriptors ?
ORB descriptors:
descriptor1 =[34, 200, 96, 158, 75, 208, 158, 230, 151, 85, 192, 131, 40, 142, 54, 64, 75, 251, 147, 195, 78, 11, 62, 245, 49, 32, 154, 59, 21, 28, 52, 222]
descriptor2 =[128, 129, 2, 129, 196, 2, 168, 101, 60, 35, 83, 18, 12, 10, 104, 73, 122, 13, 2, 176, 114, 188, 1, 198, 12, 0, 154, 68, 5, 8, 177, 128]
Thanks.
ORB descriptors are just 32 byte uchar Mat's.
the bruteforce and flann matchers do some more work, than just comparing descriptors, but if that's all you want for now, it would be a straight norm:
Mat descriptor1, descriptor2;
double dist = norm( descriptor1, descriptor2, NORM_HAMMING);
// NORM_HAMMING2 or even NORM_L1 would make sense, too.
// dist is a double, but ofc. you'd only get integer values in this case.

Haskell: How to use attoparsec in order to read a nested list from a ByteString

I have a text file (~ 300 MB large) with a nested list, similar to this one:
[[4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94, 95], [4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 87, 92, 93, 94],[4, 9, 11, 28, 30, 45, 55, 58, 61, 62, 63, 69, 74, 76, 77, 82, 85, 87, 92, 93, 94, 95]]
Here is my program to read the file into a haskell Integer list:
import qualified Data.ByteString as ByteStr
main :: IO ()
-- HOW to do the same thing but using ByteStr.readFile for file access?
main = do fContents <- readFile filePath
let numList = readNums fContents
putStrLn (show nums)
This works for small text files, but I want to use ByteString to read the file quickly. I found out that there is no read function for ByteString, instead you should write your own parser in attoparsec, since it supports parsing ByteStrings.
How can I use attoparsec to parse the nested list?
The data seems to be in JSON format, so you can use Data.Aeson decode function which works on ByteString
import qualified Data.ByteString.Lazy as BL
import Data.Aeson
import Data.Maybe
main = do fContents <- BL.readFile filePath
let numList = decode fContents :: Maybe [[Int]]
putStrLn (show $ fromJust numList)

Resources