Error while creating a binary mask using bounding box values - mask

for img in GT['image'].unique():
bbox=GT[GT['image']==img]
template = np.zeros((240,320))
for i in bbox:
cv2.rectangle(template , (int(xmin[i]) , int(ymin[i])) , (int(xmax[i]) , int(ymax[i])) , (255,255,255) ,-1)
cv2.imwrite('masked/'+img+'.jpg',template)
The error I'm facing
I've attached the error I'm getting here. Could someone please help out? I'm new to OpenCV.
Update:I made a minor change which makes the code correct and errorless but there's no output at all. The code just runs correctly without any output file.
for img in GT['image'].unique():
bbox=GT[GT['image']==img]
template = np.zeros((240,320))
j=0
for i in bbox:
cv2.rectangle(template , (int(xmin[j]) , int(ymin[j])) , (int(xmax[j]) , int(ymax[j])) , (255,255,255) ,-1)
j=j+1
cv2.imwrite('masked/'+img+'.jpg',template)

Related

How to use readClipboard to read a bitmap when using R?

I don't managed to read a bitmap which is in the Windows clipbard.
I first check the cliboard :
getClipboardFormats()
which give
[1] "bitmap" "DIB" "shell"
Then I tried :
image = readClipboard(format=2, raw=FALSE)`
and
image = readClipboard(format=2, raw=TRUE)
but I always obtain a NULL value for image !
Can someone explain to me how to do it?

Widgets run perfectly in Jupyter Notebook, but do nothing in Voila

I have several buttons which generate images. All work perfectly in Jupyter Notebook, but when I click Voila, and click the buttons, nothing happens. The first button works, but the code is very similar to run other models, yet the other buttons do not work. Is there a work around for this issue?
Edit:
My code which does not show the output when the button is clicked:
compare = {}
button9 = widgets.Button(description = "Report All")
output = widgets.Output()
display(button9, output)
dt = DecisionTreeClassifier(random_state=42)
dt = dt.fit(X_train, y_train)
y_pred = dt.predict(X_test)
compare['Decision Trees'] = [accuracy_score(y_test, y_pred), precision_score(y_test, y_pred), recall_score(y_test, y_pred), f1_score(y_test, y_pred)]
def report_button(b):
compare = pd.DataFrame.from_dict(compare).T
compare.columns = ['Accuracy', 'Precision', 'Recall', 'F1 Score']
compare = com.sort_values('Accuracy', ascending=False)
sns.heatmap(compare, center = True, fmt='.4f', cmap='Blues', annot=True)
button9.on_click(report_button)
However this code displays the output when clicked:
button3 = widgets.Button(description="Decision Trees")
output3 = widgets.Output()
display(button3, output3)
def dt_button(b):
# Decision Trees Classifier
dt = DecisionTreeClassifier(random_state=42)
dt = dt.fit(X_train, y_train)
y_pred = dt.predict(X_test)
compare['Decision Trees'] = [accuracy_score(y_test, y_pred), precision_score(y_test, y_pred_dt), recall_score(y_test, y_pred), f1_score(y_test, y_pred)]
CM = confusion_matrix(y_test, y_pred_dt)
sns.heatmap(CM, center = True, fmt='', cmap='Blues', annot=True)
plt.title('Decision Trees Confusion Matrix')
plt.show()
button3.on_click(dt_button)
Additionally, I am having the issue of MyBinder rendering my file with Voila, but after a few minutes, the MyBinder link shows Error 404.
I'm answering your last question here (about the download button) because I need to add code blocks and comments don't allow that.
You are using Panel in your notebook to do the download and so it works. For Voila you need to stick with ipywidgets-compatible solutions as I discussed earlier. You cannot just add another dashboard extension, Panel, and expect it to work in Voila
Here makes it seem this isn't as easy as it seems.
Suggested Option:
Based on https://stackoverflow.com/a/60013735/8508004 , using SVM_Confusion_Matrix.jpg as the example.
%%html
Click to Download SVM image
Options along that line can even be coded to show up dynamically after an event in VOila, see example code use.
Not suggested but could be useful for similar:
Based on https://github.com/jupyter-widgets/ipywidgets/issues/2471#issuecomment-580965788 (this just opens the image as separate and you have to right-click and save image as)
from IPython.display import display, FileLink
local_file = FileLink('./SVM_Confusion_Matrix.jpg', result_html_prefix="Click here to download: ")
display(local_file)

Saving a cropped image in R

I am using jpeg package to read an image into R. This creates an object of class nativeRaster. I take a portion of this image using [ operator. The resulting object is a matrix of integers. Attempting to save this object returns the error image must be a matrix or array of raw or real numbers. What should I do to be able to save this new image?
Below is a snippet to reproduce the error
imageFile = 'address of the jpg file'
outputFile = 'new file to write into'
image = jpeg::readJPEG(imageFile, native=TRUE)
output = image[1:10,1:10]
writeJPEG(image = output, target = outputFile)
I think the function writeJPEG takes image of type nativeRaster. I am not entirely sure about this but converting class of output to nativeRaster works for me.
class(output) <- "nativeRaster"
writeJPEG(image = output, target = outputFile)
Even though I was unable to find a solution, I am working around this by using solely imagemagick to crop the image.
system(paste('identify',
imageFile), intern = TRUE) %>%
regmatches(.,regexpr("(?<=[ ])[0-9]*?x[0-9]*?(?=[ ])",.,perl=T)) %>%
strsplit('x') %>% .[[1]] %>% as.double
will return the dimensions of the image and
system(paste0('convert "',imageFile,
'" -crop ',
sizeX,
'x',
sizeY,
'+',
beginningX,
'+',
beginningY,
' "',
outputFile,'"'))
will crop the image and save it to outputFile
Here sizeX and sizeY are desired dimensions of the cropped image and beginningX and beginningY designate the top left corner of the crop site on the image.

QHelpSearchEngine issue to show the QHelpSearchResultWidget data

Hi Can any one explain me how the 'typed text' in QHelpSearchQueryWidget gets parsed and resulting HTML links gets displayed onto the QHelpSearchResultWidget.
i am using the QtHelpEngine for my application. The HTMLs as mentioned in .qhp , are showing in mi TOC and index tabs. BUT the search tab , where i included the QHelpSearchQueryWidget , and QHelpSearchResultWidget does not work.
i have tested the .qhc file in assistant , and , when i type like "all" in QHelpSearchQueryWidget it shows me the links in QHelpSearchResultWidget . But the same .qhc when used in code in my application does show show any result in QHelpSearchResultWidget.
This is the slot method i have written to , capture the entered text in QHelpSearchQueryWidget i.e "all" , and set this to QHelpSearchEngine.
and expecting the count >0 , and QHelpSearchResultWidget to be updated with related HTML links where the word "all" exists.
void CHelpSearchWidgetSample::slotSearch() const
{
QList<QHelpSearchQuery> queries = m_searchEngine->queryWidget()->query();
foreach (const QHelpSearchQuery &query, queries)
{
foreach (QString word, query.wordList)
qDebug()<<"word :"<<word; // (O/P : "all")
}
m_searchEngine->search(queries);
qDebug()<<"Hit cnt : "<<m_searchEngine->hitCount(); // O/P : Hit cnt :0
}
please guide me to solve this issue.

Google maps API v3 doesnt get the coordinates

this is my code in Qlickview:
let noRows = NoOfRows('GoogleMaps')-1;
for i=0 to $(noRows)
let a=peek('CUSTACCOUNT',$(i),'GoogleMaps');
let b=peek('Adresa',$(i),'GoogleMaps');
Data:
LOAD
'$(a)' as [Kupac šifra],
'$(b)' as Adresa,
subfield([Response/Placemark/Point/coordinates], ',' ,1) AS longitude,
subfield([Response/Placemark/Point/coordinates], ',' ,2) AS latitude
FROM [http://maps.googleapis.com/maps/geo?q=$(b)&output=xml&oe=utf8&key=AIzaSyBByoqS6QmwjSOSRDIOxRe82cUW-iLYJo4] (XmlSimple, Table is [kml]);
next i;
The "output" looks like this:
Data:
LOAD
'454874' as [Kupac šifra],
'Frankfurt Deutschland' as Adresa,
subfield([Response/Placemark/Point/coordinates], ',' ,1) AS longitude,
subfield([Response/Placemark/Point/coordinates], ',' ,2) AS latitude
FROM [http://maps.googleapis.com/maps/geo?q=Frankfurt Deutschland&output=xml&oe=utf8&key=AIzaSyBByoqS6QmwjSOSRDIOxRe82cUW-iLYJo4] (XmlSimple, Table is [kml])
The communication with google doesnt work, there are no coordinates beeing returned. Can somebody pls help me?
I'm facing the same issue and found following:
https://developers.google.com/maps/documentation/geocoding/?hl=de
Since 8.3.2013 the geocoding API 2.0 is no more supported.
New coding is:
http://maps.googleapis.com/maps/api/geocode/output?parameters
next update:
please refer to this link:
http://community.qlikview.com/thread/46602
This coding gets state from google as well and in my case I get 610 = bad key
http://community.qlikview.com/servlet/JiveServlet/download/188551-30764/QVGeocodeur.qvw
last update:
if you modify your url with this string, you will see the status:
[http://maps.googleapis.com/maps/api/geocode/xml?address=$(vAddress)+fr&output=csv&oe=utf8&sensor=false&key=AIzaSyBByoqS6QmwjSOSRDIOxRe82cUW-iLYJo4]
Mine is still REQUEST_DENIED. I guess it's maybe our domain is at google's price list and they avait we do register as "google maps api for companies".
Solution is:
Table:
ADD LOAD
'$(i)' as Rowno ,
#1,
#2,
#3 as latitude,
#4 as longitude
FROM
[http://maps.googleapis.com/maps/api/geocode/json?address=$(vAddress)&sensor=false]
BE AVARE, that your postal Data are concatenated with
,+
like in the example:
http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
do this trick, it's definitelly working:
http://www.qvsource.com/wiki/General-Web-Connector-For-QlikView.ashx#Example_2
1) open QV Script
2) open wizard Web File
3) copy&paste this link http://maps.google.com/maps/api/geocode/XMLaddress=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false
4) choose XML
5) three tables will be generated, just to simplify the queries use only GeoCodeResponse:
6) Data in address do not have to include any special letters (Ö => Oe, ...) and should be concatenated with ,+ signs
Try this:
Data:
LOAD
'454874' as [Kupac šifra],
'Frankfurt Deutschland' as Adresa,
subfield([lng], ',' ,1) AS longitude,
subfield([lat], ',' ,1) AS latitude
FROM [http://maps.googleapis.com/maps/api/geocode/xml?address=Frankfurt Deutschland&sensor=false] (XmlSimple, Table is [GeocodeResponse/result/geometry/location]);

Resources