A question on the minifying logic.
// Assumptions:
//com.example.dummy ns is available
//com.example.dummy.type is defined immutable -> Object.defineProperty
var test, test1, test2;
function execute_case(id) {
switch(id) {
case 0:
test = com.example.dummy.type;
break;
case 1:
test1 = com.example.dummy.type;
break;
case 2:
test2 = com.example.dummy.type;
break;
default:
console.log("default");
break;
}
}
the YUI compressor compresses it to,
var test,test1,test2;function execute_case(a){switch(a){case 0:
test=com.example.dummy.type;break;case 1:test1=com.example.dummy.type;break;
case 2:test2=com.example.dummy.type;break;default:console.log("default");break}};
Wouldn't it be logical for the compressor do the following as an optimization?
var test, test1, test2;
var st = com.example.dummy.type;
function execute_case(id) {
switch(id) {
case 0:
test = st;
case 1:
test1 = st;
break;
case 2:
test2 = st;
break;
default:
console.log("default");
break;
}
}
As can be seen, the compression here works out better.
var test,test1,test2;var st=com.example.dummy.type;function execute_case(a){
switch(a){case 0:test=st;case 1:test1=st;break;case 2:test2=st;break;
default:console.log("default");break}};
That optimization makes sense for uncompressed source code, but not if the file is delivered with gzip compression (which is highly recommended).
String aliasing tends to make the compressed source code larger.
See the Closure-compiler FAQ
Related
I am using openCV 4.5 and I'm using USAC to find the fundamental matrix. This works fine for specifying a USAC method:
import cv2
a,b = cv2.FindFundamentalMat(pts1, pts2, cv2.USAC_FAST)
and this works fine for specifying USAC parameters:
params = cv2.UsacParams()
params.maxIterations=700
a,b = cv2.FindFundamentalMat(pts1, pts2, params)
But I can't figure out how to specify both the method and the settings. Or does the method determine the settings?
Looking into the C++ source code, we can see that the two different ways of calling the function (with or without the UsacParams) lead to different calls to setParameters.
In conclusion, you're right that the choice of method (e.g. USAC_FAST) determines the settings (at least in C++ code).
From https://github.com/opencv/opencv/blob/4.x/modules/calib3d/src/usac/ransac_solvers.cpp
If you pass UsacParams:
void setParameters (Ptr<Model> ¶ms, EstimationMethod estimator, const UsacParams &usac_params, bool mask_needed) {
params = Model::create(usac_params.threshold, estimator, usac_params.sampler, usac_params.confidence, usac_params.maxIterations, usac_params.score);
params->setLocalOptimization(usac_params.loMethod);
params->setLOSampleSize(usac_params.loSampleSize);
params->setLOIterations(usac_params.loIterations);
params->setParallel(usac_params.isParallel);
params->setNeighborsType(usac_params.neighborsSearch);
params->setRandomGeneratorState(usac_params.randomGeneratorState);
params->maskRequired(mask_needed);
}
If you pass a method instead of UsacParams:
void setParameters (int flag, Ptr<Model> ¶ms, EstimationMethod estimator, double thr,
int max_iters, double conf, bool mask_needed) {
switch (flag) {
case USAC_DEFAULT:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_UNIFORM, conf, max_iters, ScoreMethod::SCORE_METHOD_MSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_INNER_AND_ITER_LO);
break;
case USAC_MAGSAC:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_UNIFORM, conf, max_iters, ScoreMethod::SCORE_METHOD_MAGSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_SIGMA);
params->setLOSampleSize(params->isHomography() ? 75 : 50);
params->setLOIterations(params->isHomography() ? 15 : 10);
break;
case USAC_PARALLEL:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_UNIFORM, conf, max_iters, ScoreMethod::SCORE_METHOD_MSAC);
params->setParallel(true);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_INNER_LO);
break;
case USAC_ACCURATE:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_UNIFORM, conf, max_iters, ScoreMethod::SCORE_METHOD_MSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_GC);
params->setLOSampleSize(20);
params->setLOIterations(25);
break;
case USAC_FAST:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_UNIFORM, conf, max_iters, ScoreMethod::SCORE_METHOD_MSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_INNER_AND_ITER_LO);
params->setLOIterations(5);
params->setLOIterativeIters(3);
break;
case USAC_PROSAC:
params = Model::create(thr, estimator, SamplingMethod::SAMPLING_PROSAC, conf, max_iters, ScoreMethod::SCORE_METHOD_MSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_INNER_LO);
break;
case USAC_FM_8PTS:
params = Model::create(thr, EstimationMethod::Fundamental8,SamplingMethod::SAMPLING_UNIFORM, conf, max_iters,ScoreMethod::SCORE_METHOD_MSAC);
params->setLocalOptimization(LocalOptimMethod ::LOCAL_OPTIM_INNER_LO);
break;
default: CV_Error(cv::Error::StsBadFlag, "Incorrect flag for USAC!");
}
// do not do too many iterations for PnP
if (estimator == EstimationMethod::P3P) {
if (params->getLOInnerMaxIters() > 15)
params->setLOIterations(15);
params->setLOIterativeIters(0);
}
params->maskRequired(mask_needed);
}
For more information, check out the descriptions of the different parameters here: https://docs.opencv.org/4.5.0/d1/df1/md__build_master-contrib_docs-lin64_opencv_doc_tutorials_calib3d_usac.html
I am trying to get my ESP32 + RFM95C connected to The Things Network.
The Error I recieve is simple this:
24951: EV_JOINING
24970: EV_TXSTART
426696: EV_JOIN_TXCOMPLETE: no JoinAccept
And that repeats, Here is my setup code:
static const u1_t PROGMEM APPEUI[8]= { secret stuff here };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
// This should also be in little endian format, see above.
// static const u1_t PROGMEM DEVEUI[8]= { secret stuff here };
static const u1_t PROGMEM DEVEUI[8]= { secret stuff here };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { secret stuff here };
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
static uint8_t mydata[] = "Hello, world!";
static osjob_t sendjob;
// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;
// Pin mapping
const lmic_pinmap lmic_pins = {
.nss = 5,
.rxtx = LMIC_UNUSED_PIN,
.rst = 27,
.dio = {2, 26, 25},
};
void printHex2(unsigned v) {
v &= 0xff;
if (v < 16)
Serial.print('0');
Serial.print(v, HEX);
}
void onEvent (ev_t ev) {
Serial.print(os_getTime());
Serial.print(": ");
switch(ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
Serial.println(F("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
Serial.println(F("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
Serial.println(F("EV_BEACON_TRACKED"));
break;
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
{
u4_t netid = 0;
devaddr_t devaddr = 0;
u1_t nwkKey[16];
u1_t artKey[16];
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
Serial.print("netid: ");
Serial.println(netid, DEC);
Serial.print("devaddr: ");
Serial.println(devaddr, HEX);
Serial.print("AppSKey: ");
for (size_t i=0; i<sizeof(artKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(artKey[i]);
}
Serial.println("");
Serial.print("NwkSKey: ");
for (size_t i=0; i<sizeof(nwkKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(nwkKey[i]);
}
Serial.println();
}
// Disable link check validation (automatically enabled
// during join, but because slow data rates change max TX
// size, we don't use it in this example.
LMIC_setLinkCheckMode(0);
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_RFU1:
|| Serial.println(F("EV_RFU1"));
|| break;
*/
case EV_JOIN_FAILED:
Serial.println(F("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED"));
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F("Received ack"));
if (LMIC.dataLen) {
Serial.print(F("Received "));
Serial.print(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
//Now we sleep
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
Serial.println(F("EV_LOST_TSYNC"));
break;
case EV_RESET:
Serial.println(F("EV_RESET"));
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
Serial.println(F("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
Serial.println(F("EV_LINK_ALIVE"));
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_SCAN_FOUND:
|| Serial.println(F("EV_SCAN_FOUND"));
|| break;
*/
case EV_TXSTART:
Serial.println(F("EV_TXSTART"));
break;
case EV_TXCANCELED:
Serial.println(F("EV_TXCANCELED"));
break;
case EV_RXSTART:
/* do not print anything -- it wrecks timing */
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
break;
default:
Serial.print(F("Unknown event: "));
Serial.println((unsigned) ev);
break;
}
}
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
Serial.println(F("Packet queued"));
}
// Next TX is scheduled after TX_COMPLETE event.
}
Nothing all that special, just boilerplate sketch code.
I have a Dragino LPS8 LoRaWan Gateway with these settings:
Does anyone know why my connection will not go through?
It has been a while, and I have learned a LOT more about LoRaWan since I originally posted this question. I now know that OTAA will not work with a single channel gateway such as the dragino I had shown in the pictures. A gateway such as https://www.adafruit.com/product/4345 (an 8 channel gateway) would have been a better place for me to start this project.
I use the same code in the iOS and macOSX two platforms to test, view the Runloop's activity switch, found that the results of the two platforms are not the same, what is the reason.s
Code:
1.create RunLoop Observer
CFRunLoopObserverContext context = {0,(__bridge void*)self, NULL, NULL, NULL};
_observer = CFRunLoopObserverCreate(kCFAllocatorDefault,
kCFRunLoopAllActivities,
YES,
0,
&runLoopObserverCallBack,
&context);
CFRunLoopAddObserver(CFRunLoopGetMain(), _observer, kCFRunLoopCommonModes);
2.print activity state
static void runLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info){
Monitor *monitor = (__bridge Monitor*)info;
switch (activity) {
case kCFRunLoopEntry:
NSLog(#"activity_kCFRunLoopEntry");
break;
case kCFRunLoopBeforeTimers:
NSLog(#"activity_kCFRunLoopBeforeTimers");
break;
case kCFRunLoopBeforeSources:
NSLog(#"activity_kCFRunLoopBeforeSources");
break;
case kCFRunLoopBeforeWaiting:
NSLog(#"activity_kCFRunLoopBeforeWaiting");
break;
case kCFRunLoopAfterWaiting:
NSLog(#"activity_kCFRunLoopAfterWaiting");
break;
case kCFRunLoopExit:
NSLog(#"activity_kCFRunLoopExit");
break;
default:
break;
}}
The Result:
1.iOS
iOS Result
2.macOS
MacOS Result
Why are there multiple kCFRunLoopEntry in the macOS system?
I am new to MPLAB X Harmony framework and also in working with microcontrollers. I am working on PIC32MZ2048ECH144. I wanted to transmit a simple string using USART and see it displayed in RealTerm terminal.(I have tried HyperTerminal also.) Whatever string I send, I see only junk characters being displayed. When I browsed for the solution for this problem of junk characters being displayed, there were suggestions to check for the baud rate. I have set the baud rate to be 9600 in MPLab Harmony Configurator(Options -> Harmony Framework configuration -> Drivers -> USART -> USART Driver Instance 0 -> Baud Rate -> 9600). So I used the following line in app.c to explicitly set the baud rate.(PBCLK is 100MHz). But no luck!
PLIB_USART_BaudRateSet(USART_ID_2, 100000000 ,9600);
The code for app.c file:
/*******************************************************************************
Start of File
*/
const char *string1 = "*** UART Interrupt-driven Application Example ***\r\n";
const char *string2 = "*** Type some characters and observe the LED turn ON ***\r\n";
APP_DATA appData =
{
};
APP_DRV_OBJECTS appDrvObject;
void APP_Initialize ( void )
{
appData.state = USART_ENABLE;
appData.InterruptFlag = false;
}
bool WriteString(void)
{
if(*appData.stringPointer == '\0')
{
return true;
}
while (PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, *appData.stringPointer);
appData.stringPointer++;
if(*appData.stringPointer == '\0')
{
return true;
}
}
return false;
}
bool PutCharacter(const char character)
{
if(PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, character);
return true;
}
else
return false;
}
void APP_Tasks ( void )
{
/* check the application state*/
switch ( appData.state )
{
case USART_ENABLE:
/* Enable the UART module*/
PLIB_USART_BaudRateSet(USART_ID_1, 100000000 ,9600);
PLIB_USART_Enable(USART_ID_1);
appData.stringPointer = string1;
appData.state = USART_TRANSMIT_FIRST_STRING;
break;
case USART_TRANSMIT_FIRST_STRING:
if(true == WriteString())
{
appData.state = USART_TRANSMIT_SECOND_STRING;
appData.stringPointer = string2;
}
break;
case USART_TRANSMIT_SECOND_STRING:
if(true == WriteString())
{
appData.state = USART_RECEIVE_DONE;
}
break;
case USART_RECEIVE_DONE:
if (appData.InterruptFlag)
{
if(true == PutCharacter(appData.data))
{
appData.InterruptFlag = false;
}
}
break;
default:
while (1);
}
}
/*******************************************************************************
End of File
*/
I am sorry that I cannot attach the image of the output I receive in RealTerm as I do not have enough points.
I have no clue where else the problem could be that gives the mismatch of baud rate. Any hints or help would be of great help. Thanks in advance.
Kindly apologize me for any mistakes in the post.
you are correct that it is most likely BAUD rate, but just to be sure how is the USART hooked to the computer? Do you have a translator chip since the computer is expecting +-5V? As for the BAUD, check your clocking scheme and know that PBCLK is sometimes DIV_2 of the SYSCLOCK. There is a great clocking schematic in the Harmony framework to double check your clocking and CONFIG pragmas.
While uploading some images, i get this error:
corrupt EXIF header: maximum directory nesting level reached
I'm trying to avoid the error by checking if response is false, but the error still happens.
$image = #imagecreatefromstring(file_get_contents($_FILES['fileinput']['tmp_name']));
$exif = #exif_read_data($_FILES['fileinput']['tmp_name'] ,'EXIF' ,0);
$rotation = 0;
if($exif !== false) {
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$rotation = 90;
break;
case 3:
$rotation = 180;
break;
case 6:
$rotation = 270;
break;
}
}
}
I get this error with just a few images. How can i track the error so i can skip header verification on the images that gives me the error?
There seem to be an issue with some EXIF data from some cameras like Fujifilm and some old php version. Check https://bugs.php.net/bug.php?id=66443
You may need to update php and maybe compile it from the source code.